Browse Source

calc skin

Jose Bedolla 6 years ago
parent
commit
0a4fc415a9

BIN
.DS_Store View File


BIN
src/.DS_Store View File


+ 32
- 4
src/main/java/rocks/zipcode/calcskin/CalcEngine.java View File

6
     }
6
     }
7
 
7
 
8
     public double add(double v, double v1) {
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
     public double subtract(double v, double v1) {
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
     public double multiply(double v, double v1) {
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
     public double divide(double v, double v1) {
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 View File

24
         launch(args);
24
         launch(args);
25
     }
25
     }
26
     private static final String[][] template = {
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
     private final Map<String, Button> accelerators = new HashMap<>();
33
     private final Map<String, Button> accelerators = new HashMap<>();
36
     private DoubleProperty currentValue = new SimpleDoubleProperty();
36
     private DoubleProperty currentValue = new SimpleDoubleProperty();
37
     private CalcEngine calcEngine = new CalcEngine();
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
     private Op curOp   = Op.NOOP;
41
     private Op curOp   = Op.NOOP;
42
     private Op stackOp = Op.NOOP;
42
     private Op stackOp = Op.NOOP;
84
         screen.setStyle("-fx-background-color: aquamarine;");
84
         screen.setStyle("-fx-background-color: aquamarine;");
85
         screen.setAlignment(Pos.CENTER_RIGHT);
85
         screen.setAlignment(Pos.CENTER_RIGHT);
86
         screen.setEditable(false);
86
         screen.setEditable(false);
87
-        screen.textProperty().bind(Bindings.format("%.0f", currentValue));
87
+        screen.textProperty().bind(Bindings.format("%.6f", currentValue));
88
         return screen;
88
         return screen;
89
     }
89
     }
90
 
90
 
115
             } else if ("=".equals(s)) {
115
             } else if ("=".equals(s)) {
116
                 makeEqualsButton(button);
116
                 makeEqualsButton(button);
117
             }
117
             }
118
+
118
         }
119
         }
119
 
120
 
120
         return button;
121
         return button;
127
             case "-": triggerOp.set(Op.SUBTRACT); break;
128
             case "-": triggerOp.set(Op.SUBTRACT); break;
128
             case "*": triggerOp.set(Op.MULTIPLY); break;
129
             case "*": triggerOp.set(Op.MULTIPLY); break;
129
             case "/": triggerOp.set(Op.DIVIDE);   break;
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
         return triggerOp;
137
         return triggerOp;
132
     }
138
     }
185
                     case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
191
                     case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
186
                     case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
192
                     case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
187
                     case DIVIDE:   currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
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 View File

10
     }
10
     }
11
 
11
 
12
 }
12
 }
13
+

BIN
src/test/.DS_Store View File


BIN
src/test/java/.DS_Store View File


BIN
src/test/java/rocks/.DS_Store View File


BIN
src/test/java/rocks/zipcode/.DS_Store View File