|
@@ -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" },
|
|
28
|
+ { "4", "5", "6", "*", "1/x" },
|
|
29
|
+ { "1", "2", "3", "-", "SqRt" },
|
|
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, SQUARE, SQUAREROOT, INVERT, EXPONENT}
|
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("%.3f", currentValue));
|
88
|
88
|
return screen;
|
89
|
89
|
}
|
90
|
90
|
|
|
@@ -127,10 +127,17 @@ 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.SQUARE); break;
|
|
131
|
+ case "SqRt": triggerOp.set(Op.SQUAREROOT); break;
|
|
132
|
+ case "1/x": triggerOp.set(Op.INVERT); break;
|
|
133
|
+ case "x^y": triggerOp.set(Op.EXPONENT); break;
|
|
134
|
+
|
130
|
135
|
}
|
131
|
136
|
return triggerOp;
|
132
|
137
|
}
|
133
|
138
|
|
|
139
|
+ //private void squareRoot(Button button)
|
|
140
|
+
|
134
|
141
|
private void makeOperandButton(Button button, final ObjectProperty<Op> triggerOp) {
|
135
|
142
|
button.setStyle("-fx-base: lightgray;");
|
136
|
143
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
|
@@ -185,10 +192,31 @@ public class CalcSkin extends Application {
|
185
|
192
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
193
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
194
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
195
|
+ case SQUARE: currentValue.set(calcEngine.square(currentValue.get())); break;
|
|
196
|
+ case SQUAREROOT: currentValue.set(calcEngine.squareRoot(currentValue.get())); break;
|
|
197
|
+ case INVERT: currentValue.set(calcEngine.invertNumber(currentValue.get())); break;
|
|
198
|
+ case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
|
199
|
+
|
188
|
200
|
}
|
189
|
201
|
}
|
190
|
202
|
});
|
191
|
203
|
}
|
|
204
|
+
|
|
205
|
+// private void makeSquareButton(Button button) {
|
|
206
|
+// button.setStyle("-fx-base: mistyrose;");
|
|
207
|
+// button.setOnAction(new EventHandler<ActionEvent>() {
|
|
208
|
+// @Override
|
|
209
|
+// public void handle(ActionEvent actionEvent) {
|
|
210
|
+// switch (stackOp) {
|
|
211
|
+//
|
|
212
|
+// case SQUARE:
|
|
213
|
+// currentValue.set(calcEngine.square(currentValue.get()));
|
|
214
|
+// }
|
|
215
|
+// }
|
|
216
|
+// });
|
|
217
|
+// }
|
|
218
|
+
|
|
219
|
+
|
192
|
220
|
}
|
193
|
221
|
|
194
|
222
|
|