|
@@ -14,7 +14,7 @@ public class Pemdas
|
14
|
14
|
public static String calculate(String s)
|
15
|
15
|
{
|
16
|
16
|
|
17
|
|
- System.out.println("Original " + s);
|
|
17
|
+ //System.out.println("Original " + s);
|
18
|
18
|
//String p = null;
|
19
|
19
|
//if(getBetweenBraces(s) != null)
|
20
|
20
|
//{
|
|
@@ -23,7 +23,7 @@ public class Pemdas
|
23
|
23
|
//System.out.println(p);
|
24
|
24
|
|
25
|
25
|
String e = null;
|
26
|
|
- System.out.println("expo");
|
|
26
|
+ //System.out.println("expo");
|
27
|
27
|
//create a duplicate of the method below, this one should have no print statemnts - testing purposes only.
|
28
|
28
|
//instead of the above, remove everyting except for assignment and initiailization
|
29
|
29
|
//this will work because getUpdateString2 cannot return null.
|
|
@@ -34,34 +34,34 @@ public class Pemdas
|
34
|
34
|
}
|
35
|
35
|
|
36
|
36
|
String m = null;
|
37
|
|
- System.out.println("mult");
|
|
37
|
+ //System.out.println("mult");
|
38
|
38
|
if(getUpdateString2(e,"*") != null)
|
39
|
39
|
{
|
40
|
40
|
m = getUpdateString2(e,"*");
|
41
|
41
|
}
|
42
|
42
|
|
43
|
43
|
String d = null;
|
44
|
|
- System.out.println("div");
|
|
44
|
+ //System.out.println("div");
|
45
|
45
|
if(getUpdateString2(m,"/") != null)
|
46
|
46
|
{
|
47
|
47
|
d = getUpdateString2(m,"/");
|
48
|
48
|
}
|
49
|
49
|
|
50
|
50
|
String a = null;
|
51
|
|
- System.out.println("add");
|
|
51
|
+ //System.out.println("add");
|
52
|
52
|
if(getUpdateString2(d,"+") != null)
|
53
|
53
|
{
|
54
|
54
|
a = getUpdateString2(d,"+");
|
55
|
55
|
}
|
56
|
56
|
|
57
|
57
|
String ss = null;
|
58
|
|
- System.out.println("sub");
|
|
58
|
+ //System.out.println("sub");
|
59
|
59
|
if(getUpdateString2(a,"-") != null)
|
60
|
60
|
{
|
61
|
61
|
ss = getUpdateString2(a,"-");
|
62
|
62
|
}
|
63
|
63
|
|
64
|
|
- System.out.println("calculate 1.) Answer: " + ss);
|
|
64
|
+ //System.out.println("calculate 1.) Answer: " + ss);
|
65
|
65
|
return ss;
|
66
|
66
|
|
67
|
67
|
}
|
|
@@ -98,7 +98,7 @@ public class Pemdas
|
98
|
98
|
|
99
|
99
|
if(matcher.find())
|
100
|
100
|
{
|
101
|
|
- System.out.println("searchReturnFirstString 1.) perform on " + s + ": " + matcher.group());
|
|
101
|
+ //System.out.println("searchReturnFirstString 1.) perform on " + s + ": " + matcher.group());
|
102
|
102
|
return matcher.group();
|
103
|
103
|
}
|
104
|
104
|
|
|
@@ -115,8 +115,8 @@ public class Pemdas
|
115
|
115
|
//if anything is replaced, return an updated string with the appropriate replacements
|
116
|
116
|
} else {
|
117
|
117
|
String result = target.replaceFirst(pattern, replacement);
|
118
|
|
- System.out.println("searchReplaceFirst 1.) target | pattern | replacement | result");
|
119
|
|
- System.out.println("searchReplaceFirst 2.) " + target + " | " + pattern + " | " + replacement + " | " + result);
|
|
118
|
+ //System.out.println("searchReplaceFirst 1.) target | pattern | replacement | result");
|
|
119
|
+ //System.out.println("searchReplaceFirst 2.) " + target + " | " + pattern + " | " + replacement + " | " + result);
|
120
|
120
|
return result;
|
121
|
121
|
}
|
122
|
122
|
}
|
|
@@ -150,12 +150,12 @@ public class Pemdas
|
150
|
150
|
public static String getUpdateString2(String s, String operator)
|
151
|
151
|
{
|
152
|
152
|
String f = s;
|
153
|
|
- System.out.println("getUpdateString2 1.) Input is: " + f);
|
|
153
|
+ //System.out.println("getUpdateString2 1.) Input is: " + f);
|
154
|
154
|
String pattern = "\\s?\\.?\\d+\\.?(\\d+)?\\s?\\" + operator + "\\s?\\.?\\d+\\.?(\\d+)?\\s?";
|
155
|
|
- System.out.println("getUpdateString2 2.) Pattern is " + pattern);
|
|
155
|
+ //System.out.println("getUpdateString2 2.) Pattern is " + pattern);
|
156
|
156
|
|
157
|
157
|
String occ = searchReturnFirstString(s, pattern);
|
158
|
|
- System.out.println("getUpdateString2 3.) the occurance is " + occ);
|
|
158
|
+ //System.out.println("getUpdateString2 3.) the occurance is " + occ);
|
159
|
159
|
//if we recieve a result
|
160
|
160
|
if(occ != null)
|
161
|
161
|
{
|
|
@@ -176,27 +176,27 @@ public class Pemdas
|
176
|
176
|
{
|
177
|
177
|
case "^":
|
178
|
178
|
doubleResult = Math.pow(left, right);
|
179
|
|
- System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
|
179
|
+ //System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
180
|
180
|
break;
|
181
|
181
|
|
182
|
182
|
case "+":
|
183
|
183
|
doubleResult = left + right;
|
184
|
|
- System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
|
184
|
+ //System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
185
|
185
|
break;
|
186
|
186
|
|
187
|
187
|
case "-":
|
188
|
188
|
doubleResult = left - right;
|
189
|
|
- System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
|
189
|
+ //System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
190
|
190
|
break;
|
191
|
191
|
|
192
|
192
|
case "*":
|
193
|
193
|
doubleResult = left * right;
|
194
|
|
- System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
|
194
|
+ //System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
195
|
195
|
break;
|
196
|
196
|
|
197
|
197
|
case "/":
|
198
|
198
|
doubleResult = left / right;
|
199
|
|
- System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
|
199
|
+ //System.out.println("getUpdateString2 .4) " + left + operator + right + "=" + doubleResult);
|
200
|
200
|
break;
|
201
|
201
|
|
202
|
202
|
default:
|
|
@@ -208,7 +208,7 @@ public class Pemdas
|
208
|
208
|
//String result = String.format("%.9f", doubleResult);
|
209
|
209
|
//replace the occurence of occ in s with result
|
210
|
210
|
f = searchReplaceFirst(s, result, pattern);
|
211
|
|
- System.out.println("getUpdateString2 5.) iteration completed, f: " + f + "\n");
|
|
211
|
+ //System.out.println("getUpdateString2 5.) iteration completed, f: " + f + "\n");
|
212
|
212
|
if(!f.equals(s))
|
213
|
213
|
{
|
214
|
214
|
f = getUpdateString2(f, operator);
|