-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomInstance.java
More file actions
61 lines (49 loc) · 1.44 KB
/
PolynomInstance.java
File metadata and controls
61 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//this class represent a singal polynom instance.
public class PolynomInstance {
private int variableDegree;
private double coefficient;
//default constructor
public PolynomInstance() {
this.variableDegree = 0;
this.coefficient = 0;
}
//costume constructor
public PolynomInstance(int degree, double coefficient) {
this.variableDegree = degree;
this.coefficient = coefficient;
}
//copy constructor
public PolynomInstance(PolynomInstance c) {
this.variableDegree = c.getDegree();
this.coefficient = c.getCoefficient();
}
public int getDegree() {
return this.variableDegree;
}
public double getCoefficient() {
return this.coefficient;
}
public void setCoefficient(double newcoefficient) {
this.coefficient = newcoefficient;
}
public void setDegree(int newDegree) {
this.variableDegree = newDegree;
}
public boolean isEqualTo(PolynomInstance p)
{
if(this.variableDegree == p.getDegree() && this.coefficient == p.getCoefficient())
return true;
else return false;
}
//stringing the instance by formal presentation rules
public String toString()
{
if(this.variableDegree < 0) //"aX^(-b)
return this.coefficient + "X^(" + this.variableDegree + ")";
if(this.variableDegree == 0) //"a"
return "" + this.coefficient;
if(this.variableDegree == 1) //"aX"
return this.coefficient + "X";
return this.coefficient + "X^" + this.variableDegree; //"aX^b
}
}