Xcuello 6 年 前
コミット
d6116b0f10
共有3 個のファイルを変更した73 個の追加61 個の削除を含む
  1. バイナリ
      .DS_Store
  2. 40
    38
      Calculations.java
  3. 33
    23
      package.bluej

バイナリ
.DS_Store ファイルの表示


+ 40
- 38
Calculations.java ファイルの表示

@@ -8,9 +8,9 @@ public class Calculations
8 8
     public static ArrayList<String> library = new ArrayList<String>();
9 9
     public static String invalidArgumentsAmountError = "You have entered an invalid amount of arguments. Please only use two arguments, or switch to PEMDAS";
10 10
     public static Pemdas pemdas = new Pemdas();
11
-    
11
+
12 12
     public Calculations(){
13
-   
13
+
14 14
     library.add("multiply");
15 15
     library.add("divide");
16 16
     library.add("subtract");
@@ -27,7 +27,7 @@ public class Calculations
27 27
     library.add("resetM");
28 28
     library.add("recallM");
29 29
     library.add("displayM");
30
-        
30
+
31 31
     }
32 32
 
33 33
     public static String getCommand(String userInput)
@@ -35,7 +35,7 @@ public class Calculations
35 35
         boolean foundCommand = false;
36 36
         String command = "";
37 37
         String result = "";
38
-        
38
+
39 39
         String[] inputArr = userInput.split(" ");
40 40
         for(int i = 0; i < library.size(); i ++)
41 41
         {
@@ -47,43 +47,43 @@ public class Calculations
47 47
                 break;
48 48
             }
49 49
         }
50
-        
50
+
51 51
         switch(command)
52 52
         {
53 53
             case "multiply":
54 54
                 result = Multiply(userInput);
55 55
             break;
56
-            
56
+
57 57
             case "divide":
58 58
                 result = Divide(userInput);
59 59
             break;
60
-            
60
+
61 61
             case "add":
62 62
                 result = Add(userInput);
63 63
             break;
64
-            
64
+
65 65
             case "subtract":
66 66
                 result = Subtract(userInput);
67 67
             break;
68
-            
68
+
69 69
             case "invertS":
70 70
                 result = InvertSign(userInput);
71 71
             break;
72
-            
72
+
73 73
             case "invertN":
74 74
                 result = InvertNumber(userInput);
75
-            break;   
76
-            
75
+            break;
76
+
77 77
             case "clear":
78 78
                  Clear();
79 79
             break;
80 80
         }
81 81
         return result;
82 82
     }
83
-    
83
+
84 84
     public static ArrayList<Double> getNumbers(String userInput){
85 85
         ArrayList<Double> results = new ArrayList<Double>();
86
-        
86
+
87 87
         //takes in a string
88 88
         //finds the first occurence of a number
89 89
         //store it as a double ( left )
@@ -94,27 +94,27 @@ public class Calculations
94 94
         //if the size of the arraylist is 2
95 95
             //return the array list
96 96
         //else return null'
97
-        
97
+
98 98
         Pattern pattern = Pattern.compile("\\s?\\-?\\.?\\d+\\.?(\\d+)?\\s?");
99 99
         Matcher matcher = pattern.matcher(userInput);
100
-        
100
+
101 101
         while(matcher.find()){
102 102
             String number = matcher.group().trim();
103 103
             Double deci = Double.valueOf(number);
104 104
 
105 105
             results.add(deci);
106 106
         }
107
-        
107
+
108 108
         if(results.size() == 2)
109
-        { 
109
+        {
110 110
             return results;
111 111
         }
112 112
         return null;
113 113
     }
114
-    
114
+
115 115
     public static ArrayList<Double> getNumber(String userInput){
116 116
         ArrayList<Double> results = new ArrayList<Double>();
117
-        
117
+
118 118
         //takes in a string
119 119
         //finds the first occurence of a number
120 120
         //store it as a double ( left )
@@ -125,27 +125,27 @@ public class Calculations
125 125
         //if the size of the arraylist is 2
126 126
             //return the array list
127 127
         //else return null'
128
-        
128
+
129 129
         Pattern pattern = Pattern.compile("\\s?\\-?\\.?\\d+\\.?(\\d+)?\\s?");
130 130
         Matcher matcher = pattern.matcher(userInput);
131
-        
131
+
132 132
         while(matcher.find()){
133 133
             String number = matcher.group().trim();
134 134
             Double deci = Double.valueOf(number);
135
-            
135
+
136 136
             results.add(deci);
137
-            
137
+
138 138
         }
139
-        
139
+
140 140
         if(results.size() == 1)
141
-        { 
141
+        {
142 142
             System.out.println(results.get(0));
143 143
             return results;
144 144
         }
145
-        
145
+
146 146
         return null;
147 147
     }
148
-    
148
+
149 149
     public static String Multiply(String userInput)
150 150
     {
151 151
         String result = "";
@@ -175,9 +175,9 @@ public class Calculations
175 175
         } else {
176 176
             return invalidArgumentsAmountError;
177 177
         }
178
-        
179
-        
180
-    } 
178
+
179
+
180
+    }
181 181
 
182 182
         public static String Add(String userInput)
183 183
     {
@@ -191,9 +191,9 @@ public class Calculations
191 191
         } else {
192 192
             return invalidArgumentsAmountError;
193 193
         }
194
-        
194
+
195 195
     }
196
-    
196
+
197 197
     public static String Subtract(String userInput)
198 198
     {
199 199
         //perform the operation
@@ -209,24 +209,26 @@ public class Calculations
209 209
         } else {
210 210
             return invalidArgumentsAmountError;
211 211
         }
212
-        
212
+
213 213
     }
214
- 
214
+
215 215
     public static String InvertSign(String userInput)
216 216
     {
217
+      ArrayList <Double> number1 = getNumber(userInput);
218
+      return number.get(0) * -1;
217 219
         //perform the operation
218 220
         //convert to string
219 221
         //return string
220 222
         return null;
221
-    }  
222
-    
223
+    }
224
+
223 225
     public static String InvertNumber(String userInput)
224 226
     {
225 227
         //perform the operation
226 228
         //convert to string
227 229
         //return string
228 230
         return null;
229
-    } 
231
+    }
230 232
 
231 233
     public static void Clear()
232 234
     {

+ 33
- 23
package.bluej ファイルの表示

@@ -1,29 +1,32 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Calculations
2
+dependency1.from=Calculations
3
+dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=MainApplication
6
-dependency2.to=Console
5
+dependency2.from=Calculations
6
+dependency2.to=Pemdas
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=Calculations
9
-dependency3.to=Console
8
+dependency3.from=MainApplication
9
+dependency3.to=Calculations
10 10
 dependency3.type=UsesDependency
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
11
+dependency4.from=MainApplication
12
+dependency4.to=Console
13
+dependency4.type=UsesDependency
14
+editor.fx.0.height=707
15
+editor.fx.0.width=800
16
+editor.fx.0.x=240
17
+editor.fx.0.y=23
18
+objectbench.height=196
16 19
 objectbench.width=595
17 20
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.685099846390169
19
-package.editor.height=439
21
+package.divider.vertical=0.6857585139318886
22
+package.editor.height=436
20 23
 package.editor.width=493
21 24
 package.editor.x=35
22 25
 package.editor.y=23
23
-package.frame.height=709
26
+package.frame.height=704
24 27
 package.frame.width=619
25
-package.numDependencies=3
26
-package.numTargets=3
28
+package.numDependencies=4
29
+package.numTargets=4
27 30
 package.showExtends=true
28 31
 package.showUses=true
29 32
 project.charset=UTF-8
@@ -40,16 +43,23 @@ target1.width=100
40 43
 target1.x=240
41 44
 target1.y=140
42 45
 target2.height=50
43
-target2.name=Console
46
+target2.name=Pemdas
44 47
 target2.showInterface=false
45 48
 target2.type=ClassTarget
46 49
 target2.width=80
47
-target2.x=30
48
-target2.y=200
50
+target2.x=70
51
+target2.y=10
49 52
 target3.height=50
50
-target3.name=MainApplication
53
+target3.name=Console
51 54
 target3.showInterface=false
52 55
 target3.type=ClassTarget
53
-target3.width=120
54
-target3.x=70
55
-target3.y=70
56
+target3.width=80
57
+target3.x=30
58
+target3.y=200
59
+target4.height=50
60
+target4.name=MainApplication
61
+target4.showInterface=false
62
+target4.type=ClassTarget
63
+target4.width=120
64
+target4.x=70
65
+target4.y=70