|
@@ -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, EXPONENT }
|
|
39
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE, EXPONENT, SQUARE, SQRROOT, INVERSE }
|
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
|
|
|
@@ -114,12 +114,14 @@ public class CalcSkin extends Application {
|
114
|
114
|
makeClearButton(button);
|
115
|
115
|
} else if ("=".equals(s)) {
|
116
|
116
|
makeEqualsButton(button);
|
117
|
|
- } else if ("x²".equals(s)) {
|
118
|
|
- makeSingleIntegerButton(button);
|
119
|
|
- } else if ("x⁻¹".equals(s)) {
|
120
|
|
- makeSingleIntegerButton(button);
|
121
|
|
- } else if ("√x".equals(s)) {
|
122
|
|
- makeSingleIntegerButton(button);
|
|
117
|
+ } else if ("xⁿ".equals((s))) {
|
|
118
|
+ makeSingleIntegerButtons(button);
|
|
119
|
+ } else if ("x²".equals((s))) {
|
|
120
|
+ makeSingleIntegerButtons(button);
|
|
121
|
+ } else if ("√x".equals((s))) {
|
|
122
|
+ makeSingleIntegerButtons(button);
|
|
123
|
+ } else if ("x⁻¹".equals((s))) {
|
|
124
|
+ makeSingleIntegerButtons(button);
|
123
|
125
|
}
|
124
|
126
|
}
|
125
|
127
|
|
|
@@ -133,10 +135,11 @@ public class CalcSkin extends Application {
|
133
|
135
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
134
|
136
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
135
|
137
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
138
|
+ case "xⁿ": triggerOp.set(Op.EXPONENT); break;
|
136
|
139
|
case "x²": triggerOp.set(Op.SQUARE); break;
|
137
|
140
|
case "√x": triggerOp.set(Op.SQRROOT); break;
|
138
|
141
|
case "x⁻¹": triggerOp.set(Op.INVERSE); break;
|
139
|
|
- case "xⁿ": triggerOp.set(Op.EXPONENT); break;
|
|
142
|
+
|
140
|
143
|
}
|
141
|
144
|
return triggerOp;
|
142
|
145
|
}
|
|
@@ -185,19 +188,6 @@ public class CalcSkin extends Application {
|
185
|
188
|
});
|
186
|
189
|
}
|
187
|
190
|
|
188
|
|
- private void makeSingleIntegerButton(Button button) {
|
189
|
|
- button.setStyle("-fx-base: azure");
|
190
|
|
- button.setOnAction(new EventHandler<ActionEvent>() {
|
191
|
|
- @Override
|
192
|
|
- public void handle(ActionEvent actionEvent) {
|
193
|
|
- switch (stackOp) {
|
194
|
|
- case SQUARE: currentValue.set(calcEngine.squ(currentValue.get())); break;
|
195
|
|
- case INVERSE: currentValue.set(calcEngine.inv(currentValue.get())); break;
|
196
|
|
- case SQRROOT: currentValue.set(calcEngine.sqrt(currentValue.get())); break;
|
197
|
|
- }
|
198
|
|
- }});
|
199
|
|
- }
|
200
|
|
-
|
201
|
191
|
private void makeEqualsButton(Button button) {
|
202
|
192
|
button.setStyle("-fx-base: ghostwhite;");
|
203
|
193
|
button.setOnAction(new EventHandler<ActionEvent>() {
|
|
@@ -208,11 +198,23 @@ public class CalcSkin extends Application {
|
208
|
198
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
209
|
199
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
210
|
200
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
211
|
|
- case EXPONENT: currentValue.set(calcEngine.exp(previousValue.get(), currentValue.get())); break;
|
|
201
|
+ case EXPONENT: currentValue.set(calcEngine.exp(previousValue.get(),currentValue.get())); break;
|
212
|
202
|
}
|
213
|
203
|
}
|
214
|
204
|
});
|
215
|
205
|
}
|
216
|
|
-}
|
217
|
|
-
|
218
|
206
|
|
|
207
|
+ private void makeSingleIntegerButtons(Button button) {
|
|
208
|
+ button.setStyle("-fx-base: azure;");
|
|
209
|
+ button.setOnAction(new EventHandler<ActionEvent>() {
|
|
210
|
+ @Override
|
|
211
|
+ public void handle(ActionEvent actionEvent) {
|
|
212
|
+ switch (stackOp) {
|
|
213
|
+ case SQUARE: currentValue.set(calcEngine.squ(currentValue.get())); break;
|
|
214
|
+ case SQRROOT: currentValue.set(calcEngine.sqrt(currentValue.get())); break;
|
|
215
|
+ case INVERSE: currentValue.set(calcEngine.inv(currentValue.get())); break;
|
|
216
|
+ }
|
|
217
|
+ }
|
|
218
|
+ });
|
|
219
|
+ }
|
|
220
|
+}
|