|
@@ -24,10 +24,11 @@ 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", "sin" ,"sroot","/"},
|
|
28
|
+ { "4", "5", "6", "cos","xsqu","*" },
|
|
29
|
+ { "1", "2", "3", "tan"," power","-" },
|
|
30
|
+ { "0", "c", "=", "inverse","Mod","+" }
|
|
31
|
+
|
31
|
32
|
};
|
32
|
33
|
|
33
|
34
|
private final Map<String, Button> accelerators = new HashMap<>();
|
|
@@ -36,7 +37,7 @@ public class CalcSkin extends Application {
|
36
|
37
|
private DoubleProperty currentValue = new SimpleDoubleProperty();
|
37
|
38
|
private CalcEngine calcEngine = new CalcEngine();
|
38
|
39
|
|
39
|
|
- private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
|
|
40
|
+ private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE,SIN,COS,TAN,INVERSE,SROOT,XSQU,POWER,MOD }
|
40
|
41
|
|
41
|
42
|
private Op curOp = Op.NOOP;
|
42
|
43
|
private Op stackOp = Op.NOOP;
|
|
@@ -81,10 +82,10 @@ public class CalcSkin extends Application {
|
81
|
82
|
|
82
|
83
|
private TextField createScreen() {
|
83
|
84
|
final TextField screen = new TextField();
|
84
|
|
- screen.setStyle("-fx-background-color: aquamarine;");
|
|
85
|
+ screen.setStyle("-fx-background-color: pink;");
|
85
|
86
|
screen.setAlignment(Pos.CENTER_RIGHT);
|
86
|
87
|
screen.setEditable(false);
|
87
|
|
- screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
|
88
|
+ screen.textProperty().bind(Bindings.format("%.0f", currentValue));
|
88
|
89
|
return screen;
|
89
|
90
|
}
|
90
|
91
|
|
|
@@ -122,11 +123,21 @@ public class CalcSkin extends Application {
|
122
|
123
|
|
123
|
124
|
private ObjectProperty<Op> determineOperand(String s) {
|
124
|
125
|
final ObjectProperty<Op> triggerOp = new SimpleObjectProperty<>(Op.NOOP);
|
|
126
|
+ s = s.toLowerCase();
|
125
|
127
|
switch (s) {
|
126
|
128
|
case "+": triggerOp.set(Op.ADD); break;
|
127
|
129
|
case "-": triggerOp.set(Op.SUBTRACT); break;
|
128
|
130
|
case "*": triggerOp.set(Op.MULTIPLY); break;
|
129
|
131
|
case "/": triggerOp.set(Op.DIVIDE); break;
|
|
132
|
+ case "sin": triggerOp.set(Op.SIN); break;
|
|
133
|
+ case "cos": triggerOp.set(Op.COS); break;
|
|
134
|
+ case "tan": triggerOp.set(Op.TAN); break;
|
|
135
|
+ case "inverse": triggerOp.set(Op.INVERSE); break;
|
|
136
|
+ case "sroot": triggerOp.set(Op.SROOT); break;
|
|
137
|
+ case "xsqu": triggerOp.set(Op.XSQU ); break;
|
|
138
|
+ case "power": triggerOp.set(Op.POWER); break;
|
|
139
|
+ case "mod": triggerOp.set(Op.MOD); break;
|
|
140
|
+
|
130
|
141
|
}
|
131
|
142
|
return triggerOp;
|
132
|
143
|
}
|
|
@@ -185,6 +196,14 @@ public class CalcSkin extends Application {
|
185
|
196
|
case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
|
186
|
197
|
case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
|
187
|
198
|
case DIVIDE: currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
|
|
199
|
+ case SIN: currentValue.set(calcEngine.sin( currentValue.get())); break;
|
|
200
|
+ case COS: currentValue.set(calcEngine.cos( currentValue.get()) ); break;
|
|
201
|
+ case TAN: currentValue.set(calcEngine.tan( currentValue.get())); break;
|
|
202
|
+ case INVERSE : currentValue.set(calcEngine.inverse(currentValue.get())); break;
|
|
203
|
+ case SROOT : currentValue.set(calcEngine.sroot(currentValue.get())); break;
|
|
204
|
+ case XSQU : currentValue.set(calcEngine.xsqu(currentValue.get())); break;
|
|
205
|
+ case POWER : currentValue.set(calcEngine.power(previousValue.get(),currentValue.get())); break;
|
|
206
|
+ case MOD: currentValue.set(calcEngine.mod(previousValue.get(),currentValue.get())); break;
|
188
|
207
|
}
|
189
|
208
|
}
|
190
|
209
|
});
|