|
@@ -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", "*", "√" },
|
|
29
|
+ { "1", "2", "3", "-", "1/x"},
|
|
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, SQUAREROOT, SQUARENUMBER, INVERSE, 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("%.6f", currentValue));
|
88
|
88
|
return screen;
|
89
|
89
|
}
|
90
|
90
|
|
|
@@ -115,6 +115,7 @@ public class CalcSkin extends Application {
|
115
|
115
|
} else if ("=".equals(s)) {
|
116
|
116
|
makeEqualsButton(button);
|
117
|
117
|
}
|
|
118
|
+
|
118
|
119
|
}
|
119
|
120
|
|
120
|
121
|
return button;
|
|
@@ -127,6 +128,11 @@ public class CalcSkin extends Application {
|
127
|
128
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
129
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
130
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
131
|
+ case "√": triggerOp.set(Op.SQUAREROOT); break;
|
|
132
|
+ case "x^2": triggerOp.set(Op.SQUARENUMBER); break;
|
|
133
|
+ case "1/x": triggerOp.set(Op.INVERSE); break;
|
|
134
|
+ case "x^y": triggerOp.set(Op.EXPONENT); break;
|
|
135
|
+
|
130
|
136
|
}
|
131
|
137
|
return triggerOp;
|
132
|
138
|
}
|
|
@@ -185,10 +191,31 @@ public class CalcSkin extends Application {
|
185
|
191
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
192
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
193
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
194
|
+ case SQUAREROOT: currentValue.set(calcEngine.squareRoot(currentValue.getValue())); break;
|
|
195
|
+ case SQUARENUMBER: currentValue.set(calcEngine.squareNumber(currentValue.getValue())); break;
|
|
196
|
+ case INVERSE: currentValue.set(calcEngine.inverse(currentValue.getValue())); break;
|
|
197
|
+ case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
188
|
198
|
}
|
189
|
199
|
}
|
190
|
200
|
});
|
191
|
201
|
}
|
|
202
|
+
|
|
203
|
+// private void sigleButton(Button button) {
|
|
204
|
+// button.setStyle("-fx-base: ghostwhite;");
|
|
205
|
+// button.setOnAction(new EventHandler<ActionEvent>() {
|
|
206
|
+// @Override
|
|
207
|
+// public void handle(ActionEvent actionEvent) {
|
|
208
|
+// switch (stackOp) {
|
|
209
|
+//
|
|
210
|
+//
|
|
211
|
+// case SQUAREROOT: currentValue.set(calcEngine.squareRoot(previousValue.get(), currentValue.get())); break;
|
|
212
|
+// case SQUARENUMBER: currentValue.set(calcEngine.squareNumber(previousValue.get(), currentValue.get())); break;
|
|
213
|
+// case INVERSE: currentValue.set(calcEngine.inverse(currentValue.get())); break;
|
|
214
|
+// case EXPONENT: currentValue.set(calcEngine.exponent(previousValue.get(), currentValue.get())); break;
|
|
215
|
+// }
|
|
216
|
+// }
|
|
217
|
+// });
|
|
218
|
+ // }
|
192
|
219
|
}
|
193
|
220
|
|
194
|
221
|
|