|
@@ -24,10 +24,10 @@ public class CalcSkin extends Application {
|
24
|
24
|
launch(args);
|
25
|
25
|
}
|
26
|
26
|
private static final String[][] template = {
|
27
|
|
- { "7", "8", "9", "/" },
|
28
|
|
- { "4", "5", "6", "*" },
|
29
|
|
- { "1", "2", "3", "-" },
|
30
|
|
- { "0", "c", "=", "+" }
|
|
27
|
+ { "7", "8", "9", "/", "x^2", "SINE"},
|
|
28
|
+ { "4", "5", "6", "*", "√", "COSINE"},
|
|
29
|
+ { "1", "2", "3", "-", "1/x","TAN" },
|
|
30
|
+ { "0", "c", "=", "+", "x^y" }
|
31
|
31
|
};
|
32
|
32
|
|
33
|
33
|
private final Map<String, Button> accelerators = new HashMap<>();
|
|
@@ -36,7 +36,7 @@ public class CalcSkin extends Application {
|
36
|
36
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
37
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
38
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
39
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARED, SROOT, INVERSE, EXPONENT, SINE, COSINE, TAN }
|
40
|
40
|
|
41
|
41
|
private Op curOp = Op.NOOP;
|
42
|
42
|
private Op stackOp = Op.NOOP;
|
|
@@ -84,7 +84,7 @@ public class CalcSkin extends Application {
|
84
|
84
|
screen.setStyle("-fx-background-color: aquamarine;");
|
85
|
85
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
86
|
screen.setEditable(false);
|
87
|
|
- screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
87
|
+ screen.textProperty().bind(Bindings.format("%.2f", currentValue));
|
88
|
88
|
return screen;
|
89
|
89
|
}
|
90
|
90
|
|
|
@@ -127,6 +127,13 @@ public class CalcSkin extends Application {
|
127
|
127
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
128
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
129
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
130
|
+ case "x^2": triggerOp.set(Op.SQUARED); break;
|
|
131
|
+ case "√": triggerOp.set(Op.SROOT); break;
|
|
132
|
+ case "1/x": triggerOp.set(Op.INVERSE); break;
|
|
133
|
+ case "x^y": triggerOp.set(Op.EXPONENT); break;
|
|
134
|
+ case "SINE": triggerOp.set(Op.SINE); break;
|
|
135
|
+ case "COSINE": triggerOp.set(Op.COSINE); break;
|
|
136
|
+ case "TAN": triggerOp.set(Op.TAN); break;
|
130
|
137
|
}
|
131
|
138
|
return triggerOp;
|
132
|
139
|
}
|
|
@@ -181,10 +188,18 @@ public class CalcSkin extends Application {
|
181
|
188
|
@Override
|
182
|
189
|
public void handle(ActionEvent actionEvent) {
|
183
|
190
|
switch (stackOp) {
|
|
191
|
+ case NOOP:
|
184
|
192
|
case ADD: currentValue.set(calcEngine.add(previousValue.get(), currentValue.get())); break;
|
185
|
193
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
194
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
195
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
196
|
+ case SQUARED: currentValue.set(calcEngine.squared(previousValue.get())); break;
|
|
197
|
+ case SROOT: currentValue.set(calcEngine.squareRoot(currentValue.get())); break;
|
|
198
|
+ case INVERSE: currentValue.set(calcEngine.inverse(previousValue.get())); break;
|
|
199
|
+ case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
|
200
|
+ case SINE: currentValue.set(calcEngine.calcSin(previousValue.get())); break;
|
|
201
|
+ case COSINE: currentValue.set(calcEngine.calcCos(previousValue.get())); break;
|
|
202
|
+ case TAN: currentValue.set(calcEngine.calcTan(previousValue.get())); break;
|
188
|
203
|
}
|
189
|
204
|
}
|
190
|
205
|
});
|