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

Merge branch 'master' of ElliottStansbury/ZCW-MacroLabs-OOP-ScientificCalculator into master

jonathan-hinds 6 лет назад
Родитель
Сommit
34a13fedbc
2 измененных файлов: 86 добавлений и 30 удалений
  1. 69
    6
      Calculations.java
  2. 17
    24
      package.bluej

+ 69
- 6
Calculations.java Просмотреть файл

@@ -101,6 +101,7 @@ public class Calculations
101 101
         while(matcher.find()){
102 102
             String number = matcher.group().trim();
103 103
             Double deci = Double.valueOf(number);
104
+
104 105
             results.add(deci);
105 106
         }
106 107
         
@@ -111,6 +112,40 @@ public class Calculations
111 112
         return null;
112 113
     }
113 114
     
115
+    public static ArrayList<Double> getNumber(String userInput){
116
+        ArrayList<Double> results = new ArrayList<Double>();
117
+        
118
+        //takes in a string
119
+        //finds the first occurence of a number
120
+        //store it as a double ( left )
121
+        //add this to the arraylist
122
+        //find the second occurence of a number
123
+        //store it as a double (right)
124
+        //add this to the array list
125
+        //if the size of the arraylist is 2
126
+            //return the array list
127
+        //else return null'
128
+        
129
+        Pattern pattern = Pattern.compile("\\s?\\-?\\.?\\d+\\.?(\\d+)?\\s?");
130
+        Matcher matcher = pattern.matcher(userInput);
131
+        
132
+        while(matcher.find()){
133
+            String number = matcher.group().trim();
134
+            Double deci = Double.valueOf(number);
135
+            
136
+            results.add(deci);
137
+            
138
+        }
139
+        
140
+        if(results.size() == 1)
141
+        { 
142
+            System.out.println(results.get(0));
143
+            return results;
144
+        }
145
+        
146
+        return null;
147
+    }
148
+    
114 149
     public static String Multiply(String userInput)
115 150
     {
116 151
         String result = "";
@@ -130,15 +165,33 @@ public class Calculations
130 165
         //perform the operation
131 166
         //convert to string
132 167
         //return string
133
-        return null;
168
+        String result = "";
169
+        ArrayList<Double> results = getNumbers(userInput);
170
+        if(results != null)
171
+        {
172
+            Double quotient = results.get(0) / results.get(1);
173
+            result = String.valueOf(quotient);
174
+            return result;
175
+        } else {
176
+            return invalidArgumentsAmountError;
177
+        }
178
+        
179
+        
134 180
     } 
135 181
 
136 182
         public static String Add(String userInput)
137 183
     {
138
-        //perform the operation
139
-        //convert to string
140
-        //return string
141
-        return null;
184
+        String result = "";
185
+        ArrayList<Double> results = getNumbers(userInput);
186
+        if(results != null)
187
+        {
188
+            Double sum = results.get(0) + results.get(1);
189
+            result = String.valueOf(sum);
190
+            return result;
191
+        } else {
192
+            return invalidArgumentsAmountError;
193
+        }
194
+        
142 195
     }
143 196
     
144 197
     public static String Subtract(String userInput)
@@ -146,7 +199,17 @@ public class Calculations
146 199
         //perform the operation
147 200
         //convert to string
148 201
         //return string
149
-        return null;
202
+        String result = "";
203
+        ArrayList<Double> results = getNumbers(userInput);
204
+        if(results != null)
205
+        {
206
+            Double difference = results.get(0) - results.get(1);
207
+            result = String.valueOf(difference);
208
+            return result;
209
+        } else {
210
+            return invalidArgumentsAmountError;
211
+        }
212
+        
150 213
     }
151 214
  
152 215
     public static String InvertSign(String userInput)

+ 17
- 24
package.bluej Просмотреть файл

@@ -8,22 +8,22 @@ dependency2.type=UsesDependency
8 8
 dependency3.from=Calculations
9 9
 dependency3.to=Console
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=1280
13
-editor.fx.0.x=0
14
-editor.fx.0.y=23
15
-objectbench.height=322
11
+editor.fx.0.height=1080
12
+editor.fx.0.width=1920
13
+editor.fx.0.x=-345
14
+editor.fx.0.y=-1080
15
+objectbench.height=198
16 16
 objectbench.width=595
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.5
19
-package.editor.height=306
20
-package.editor.width=477
18
+package.divider.vertical=0.685099846390169
19
+package.editor.height=439
20
+package.editor.width=493
21 21
 package.editor.x=35
22 22
 package.editor.y=23
23
-package.frame.height=716
23
+package.frame.height=709
24 24
 package.frame.width=619
25 25
 package.numDependencies=3
26
-package.numTargets=4
26
+package.numTargets=3
27 27
 package.showExtends=true
28 28
 package.showUses=true
29 29
 project.charset=UTF-8
@@ -37,26 +37,19 @@ target1.name=Calculations
37 37
 target1.showInterface=false
38 38
 target1.type=ClassTarget
39 39
 target1.width=100
40
-target1.x=310
41
-target1.y=260
40
+target1.x=240
41
+target1.y=140
42 42
 target2.height=50
43 43
 target2.name=Console
44 44
 target2.showInterface=false
45 45
 target2.type=ClassTarget
46 46
 target2.width=80
47
-target2.x=190
48
-target2.y=160
47
+target2.x=30
48
+target2.y=200
49 49
 target3.height=50
50
-target3.name=Pemdas
50
+target3.name=MainApplication
51 51
 target3.showInterface=false
52 52
 target3.type=ClassTarget
53
-target3.width=80
53
+target3.width=120
54 54
 target3.x=70
55
-target3.y=10
56
-target4.height=120
57
-target4.name=MainApplication
58
-target4.showInterface=false
59
-target4.type=ClassTarget
60
-target4.width=230
61
-target4.x=320
62
-target4.y=20
55
+target3.y=70