-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constant.java~
50 lines (37 loc) · 1.09 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
47
48
49
50
public class Constant extends Factor implements Comparable{
private double value;
private boolean hasDecimal;
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 void append(char c){
if(c == '.'){
if(hasDecimal)
throw new IllegalArgumentException("Multiple decimal exception.");
else
hasDecimal = true;
}
valueMask.append(c);
//System.out.println("Just appended "+c+" so now we have: " +valueMask);
}
public int compareTo(Object o){
if(value < ((Constant)o).doubleValue())
return -1;
else if (value == ((Constant)o).doubleValue())
return 0;
else return 1;
}
}