|
@@ -24,6 +24,8 @@ public class CalcSkin extends Application {
|
24
|
24
|
launch(args);
|
25
|
25
|
}
|
26
|
26
|
private static final String[][] template = {
|
|
27
|
+ {"sin", "cos", "tan", "-x"},
|
|
28
|
+ { "x²", "√", "xⁿ", "1/x"},
|
27
|
29
|
{ "7", "8", "9", "/" },
|
28
|
30
|
{ "4", "5", "6", "*" },
|
29
|
31
|
{ "1", "2", "3", "-" },
|
|
@@ -36,7 +38,8 @@ public class CalcSkin extends Application {
|
36
|
38
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
39
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
40
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
41
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARE, SQUAREROOT, EXPONENT,
|
|
42
|
+ INVERSE, INVERT, FINDSIN, FINDCOS, FINDTAN}
|
40
|
43
|
|
41
|
44
|
private Op curOp = Op.NOOP;
|
42
|
45
|
private Op stackOp = Op.NOOP;
|
|
@@ -127,6 +130,15 @@ public class CalcSkin extends Application {
|
127
|
130
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
131
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
132
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
133
|
+ case "x²": triggerOp.set(Op.SQUARE); break;
|
|
134
|
+ case "√": triggerOp.set(Op.SQUAREROOT); break;
|
|
135
|
+ case "xⁿ": triggerOp.set(Op.EXPONENT); break;
|
|
136
|
+ case "1/x": triggerOp.set(Op.INVERSE); break;
|
|
137
|
+ case "sin": triggerOp.set(Op.FINDSIN); break;
|
|
138
|
+ case "cos": triggerOp.set(Op.FINDCOS); break;
|
|
139
|
+ case "tan": triggerOp.set(Op.FINDTAN); break;
|
|
140
|
+ case "-x": triggerOp.set(Op.INVERT); break;
|
|
141
|
+
|
130
|
142
|
}
|
131
|
143
|
return triggerOp;
|
132
|
144
|
}
|
|
@@ -136,7 +148,37 @@ public class CalcSkin extends Application {
|
136
|
148
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
137
|
149
|
@Override
|
138
|
150
|
public void handle(ActionEvent actionEvent) {
|
139
|
|
- curOp = triggerOp.get();
|
|
151
|
+ if (triggerOp.get() == Op.SQUARE) {
|
|
152
|
+ currentValue.set(calcEngine.square(currentValue.get()));
|
|
153
|
+ stackOp = curOp;
|
|
154
|
+ curOp = Op.NOOP;
|
|
155
|
+ }else if(triggerOp.get() == Op.SQUAREROOT){
|
|
156
|
+ currentValue.set(calcEngine.squareroot(currentValue.get()));
|
|
157
|
+ stackOp = curOp;
|
|
158
|
+ curOp = Op.NOOP;
|
|
159
|
+ }else if(triggerOp.get() == Op.FINDCOS){
|
|
160
|
+ currentValue.set(calcEngine.findCos(currentValue.get()));
|
|
161
|
+ stackOp = curOp;
|
|
162
|
+ curOp = Op.NOOP;
|
|
163
|
+ }else if(triggerOp.get() == Op.FINDSIN){
|
|
164
|
+ currentValue.set(calcEngine.findSin(currentValue.get()));
|
|
165
|
+ stackOp = curOp;
|
|
166
|
+ curOp = Op.NOOP;
|
|
167
|
+ }else if(triggerOp.get() == Op.FINDTAN){
|
|
168
|
+ currentValue.set(calcEngine.findTan(currentValue.get()));
|
|
169
|
+ stackOp = curOp;
|
|
170
|
+ curOp = Op.NOOP;
|
|
171
|
+ }else if(triggerOp.get() == Op.INVERSE){
|
|
172
|
+ currentValue.set(calcEngine.inverse(currentValue.get()));
|
|
173
|
+ stackOp = curOp;
|
|
174
|
+ curOp = Op.NOOP;
|
|
175
|
+ }else if(triggerOp.get() == Op.INVERT){
|
|
176
|
+ currentValue.set(calcEngine.invert(currentValue.get()));
|
|
177
|
+ stackOp = curOp;
|
|
178
|
+ curOp = Op.NOOP;
|
|
179
|
+ } else {
|
|
180
|
+ curOp = triggerOp.get();
|
|
181
|
+ }
|
140
|
182
|
}
|
141
|
183
|
});
|
142
|
184
|
}
|
|
@@ -185,6 +227,14 @@ public class CalcSkin extends Application {
|
185
|
227
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
228
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
229
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
230
|
+ case SQUARE: currentValue.set(calcEngine.square(currentValue.get())); break;
|
|
231
|
+ case SQUAREROOT: currentValue.set(calcEngine.squareroot(previousValue.get())); break;
|
|
232
|
+ case INVERSE: currentValue.set(calcEngine.inverse(currentValue.get())); break;
|
|
233
|
+ case INVERT: currentValue.set(calcEngine.invert(currentValue.get())); break;
|
|
234
|
+ case FINDSIN: currentValue.set(calcEngine.findSin(currentValue.get())); break;
|
|
235
|
+ case FINDCOS: currentValue.set(calcEngine.findCos(currentValue.get())); break;
|
|
236
|
+ case FINDTAN: currentValue.set(calcEngine.findTan(currentValue.get())); break;
|
|
237
|
+ case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
188
|
238
|
}
|
189
|
239
|
}
|
190
|
240
|
});
|