Просмотр исходного кода

It kinda works, but not really. Its actually terrible. I need to do alot more work on it.

Akeem Cherry 6 лет назад
Родитель
Сommit
45a5f518e8

+ 8
- 4
src/main/java/rocks/zipcode/calcskin/CalcEngine.java Просмотреть файл

@@ -6,18 +6,22 @@ public class CalcEngine {
6 6
     }
7 7
 
8 8
     public double add(double v, double v1) {
9
-        return Double.NaN;
9
+
10
+        return v + v1;
10 11
     }
11 12
 
12 13
     public double subtract(double v, double v1) {
13
-        return Double.NaN;
14
+
15
+        return v - v1;
14 16
     }
15 17
 
16 18
     public double multiply(double v, double v1) {
17
-        return Double.NaN;
19
+
20
+        return v * v1;
18 21
     }
19 22
 
20 23
     public double divide(double v, double v1) {
21
-        return Double.NaN;
24
+
25
+        return v / v1;
22 26
     }
23 27
 }

+ 7
- 7
src/main/java/rocks/zipcode/calcskin/CalcSkin.java Просмотреть файл

@@ -34,7 +34,7 @@ public class CalcSkin extends Application {
34 34
 
35 35
     private DoubleProperty previousValue = new SimpleDoubleProperty();
36 36
     private DoubleProperty currentValue = new SimpleDoubleProperty();
37
-    private CalcEngine calcEngine = new CalcEngine();
37
+    private ScientificCalculator scientificCalculator = new ScientificCalculator();
38 38
 
39 39
     private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }
40 40
 
@@ -154,10 +154,10 @@ public class CalcSkin extends Application {
154 154
             @Override
155 155
             public void handle(ActionEvent actionEvent) {
156 156
                 if (curOp == Op.NOOP) {
157
-                    currentValue.set(currentValue.get() * 10 + Integer.parseInt(s));
157
+                    currentValue.set(currentValue.get() * 10 + Double.parseDouble(s));
158 158
                 } else {
159 159
                     previousValue.set(currentValue.get());
160
-                    currentValue.set(Integer.parseInt(s));
160
+                    currentValue.set(Double.parseDouble(s));
161 161
                     stackOp = curOp;
162 162
                     curOp = Op.NOOP;
163 163
                 }
@@ -181,10 +181,10 @@ public class CalcSkin extends Application {
181 181
             @Override
182 182
             public void handle(ActionEvent actionEvent) {
183 183
                 switch (stackOp) {
184
-                    case ADD:      currentValue.set(calcEngine.add(previousValue.get(), currentValue.get())); break;
185
-                    case SUBTRACT: currentValue.set(calcEngine.subtract(previousValue.get(), currentValue.get())); break;
186
-                    case MULTIPLY: currentValue.set(calcEngine.multiply(previousValue.get(), currentValue.get())); break;
187
-                    case DIVIDE:   currentValue.set(calcEngine.divide(previousValue.get(), currentValue.get())); break;
184
+                    case ADD:      currentValue.set(scientificCalculator.add(previousValue.get(), currentValue.get())); break;
185
+                    case SUBTRACT: currentValue.set(scientificCalculator.subtract(previousValue.get(), currentValue.get())); break;
186
+                    case MULTIPLY: currentValue.set(scientificCalculator.multiply(previousValue.get(), currentValue.get())); break;
187
+                    case DIVIDE:   currentValue.set(scientificCalculator.divide(previousValue.get(), currentValue.get())); break;
188 188
                 }
189 189
             }
190 190
         });

+ 26
- 0
src/main/java/rocks/zipcode/calcskin/Calculator.java Просмотреть файл

@@ -0,0 +1,26 @@
1
+package rocks.zipcode.calcskin;
2
+
3
+public class Calculator {
4
+
5
+        public double add(double v, double v1)
6
+        {
7
+            return v + v1;
8
+        }
9
+
10
+        public double multiply(double v, double v1)
11
+        {
12
+            return v * v1;
13
+        }
14
+
15
+        public double subtract(double v, double v1)
16
+        {
17
+            return v - v1;
18
+        }
19
+
20
+        public double divide(double v, double v1)
21
+        {
22
+            return v / v1;
23
+        }
24
+
25
+
26
+}

+ 20
- 0
src/main/java/rocks/zipcode/calcskin/ScientificCalculator.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package rocks.zipcode.calcskin;
2
+
3
+public class ScientificCalculator extends Calculator{
4
+
5
+    public double power(double v, double v1)
6
+    {
7
+        double c = (double)Math.pow(v, v1);
8
+        return c;
9
+    }
10
+
11
+    public double factorial (double v)
12
+    {
13
+        if(v <= 1)
14
+        {
15
+            return 1;
16
+        }
17
+        else
18
+            return v * factorial(v-1);
19
+    }
20
+}