-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstant.java
46 lines (33 loc) · 1.01 KB
/
Constant.java
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
public class Constant extends Factor implements Comparable{
private double value;
public double doubleValue() {
return Double.parseDouble(valueMask.toString());
}
public int intValue() {
return Math.round(Integer.parseInt(valueMask.toString()));
}
public Constant(char c){
//System.out.println("CHAR CONSTRUCTOR");
valueMask = new StringBuilder();
valueMask.append(c);
}
public Constant(double num){
//System.out.println("NUMBER CONSTRUCTOR");
valueMask = new StringBuilder(""+num);
this.value = num;
}
public int compareTo(Object o){
if(value < ((Constant)o).doubleValue())
return -1;
else if (value == ((Constant)o).doubleValue())
return 0;
else return 1;
}
public String toString(){
return "("+valueMask + (operations != null ? operations.toString() : "")+")";
}
public Constant(Constant c){
this.value = c.doubleValue();
operations = new OperationList(c.operations());
}
}