Jose Bedolla 6 gadus atpakaļ
vecāks
revīzija
0a4fc415a9

Binārs
.DS_Store Parādīt failu


Binārs
src/.DS_Store Parādīt failu


+ 32
- 4
src/main/java/rocks/zipcode/calcskin/CalcEngine.java Parādīt failu

@@ -6,18 +6,46 @@ public class CalcEngine {
6 6
     }
7 7
 
8 8
     public double add(double v, double v1) {
9
-        return Double.NaN;
9
+        double added = v + v1;
10
+        return added;
10 11
     }
11 12
 
12 13
     public double subtract(double v, double v1) {
13
-        return Double.NaN;
14
+        double subtracted = v - v1;
15
+        return subtracted;
14 16
     }
15 17
 
16 18
     public double multiply(double v, double v1) {
17
-        return Double.NaN;
19
+        double multiplied = v * v1;
20
+        return multiplied;
18 21
     }
19 22
 
20 23
     public double divide(double v, double v1) {
21
-        return Double.NaN;
24
+        double divided = v/v1;
25
+        return divided;
26
+    }
27
+
28
+    public double squareRoot(double v)
29
+    {
30
+        double squareR  = Math.sqrt(v);
31
+        return squareR;
32
+    }
33
+
34
+    public double squareNumber(double v)
35
+    {
36
+        double numberSquared = v * v;
37
+        return numberSquared;
38
+    }
39
+
40
+    public double inverse(double v)
41
+    {
42
+        double inversed = 1/v;
43
+        return inversed;
44
+    }
45
+
46
+    public double exponent(double v, double v1)
47
+    {
48
+
49
+        return Math.pow(v,v1);
22 50
     }
23 51
 }

+ 33
- 6
src/main/java/rocks/zipcode/calcskin/CalcSkin.java Parādīt failu

@@ -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
 

+ 1
- 0
src/main/java/rocks/zipcode/calcskin/MainApplication.java Parādīt failu

@@ -10,3 +10,4 @@ public class MainApplication {
10 10
     }
11 11
 
12 12
 }
13
+

Binārs
src/test/.DS_Store Parādīt failu


Binārs
src/test/java/.DS_Store Parādīt failu


Binārs
src/test/java/rocks/.DS_Store Parādīt failu


Binārs
src/test/java/rocks/zipcode/.DS_Store Parādīt failu