|
@@ -7,17 +7,17 @@ import java.util.Scanner;
|
7
|
7
|
* @version (10/19/18 v1.3 6:07PM)
|
8
|
8
|
*/
|
9
|
9
|
public class MainApplication {
|
10
|
|
-
|
|
10
|
+
|
11
|
11
|
public static void main(String[] args) {
|
12
|
12
|
System.out.println("It's time for the calculator.");
|
13
|
13
|
Console.printLegend();
|
14
|
14
|
Calculator calc = new Calculator();
|
15
|
|
-
|
|
15
|
+
|
16
|
16
|
double currentNum = 0;
|
17
|
17
|
double tempNum;
|
18
|
18
|
String tempString;
|
19
|
19
|
String firstValue = "";
|
20
|
|
-
|
|
20
|
+
|
21
|
21
|
try{
|
22
|
22
|
firstValue = Console.inputString();
|
23
|
23
|
if(firstValue.matches("[0-9]+")){
|
|
@@ -34,7 +34,7 @@ public class MainApplication {
|
34
|
34
|
}
|
35
|
35
|
else{
|
36
|
36
|
Console.error();
|
37
|
|
- currentNum = Console.displayChange();
|
|
37
|
+ currentNum = Double.valueOf(Console.inputString());
|
38
|
38
|
}
|
39
|
39
|
}
|
40
|
40
|
catch(Exception a)
|
|
@@ -42,101 +42,101 @@ public class MainApplication {
|
42
|
42
|
System.out.println("An error occured with the last request");
|
43
|
43
|
System.exit(0);
|
44
|
44
|
}
|
45
|
|
-
|
|
45
|
+
|
46
|
46
|
while(String.valueOf(firstValue) != "q") {
|
47
|
47
|
try{
|
48
|
48
|
switch (Console.getOperator()) {
|
49
|
49
|
case '+': //takes string input. if statement places memory value into function, else converts to double
|
50
|
|
- tempString = Console.inputString();
|
51
|
|
- if(tempString.equals("R")){
|
52
|
|
- tempNum = calc.getMemory();
|
53
|
|
- } else {
|
54
|
|
- tempNum = Double.valueOf(tempString);
|
55
|
|
- }
|
56
|
|
- currentNum = calc.add(currentNum, tempNum);
|
57
|
|
- break;
|
|
50
|
+ tempString = Console.inputString();
|
|
51
|
+ if(tempString.equals("R")){
|
|
52
|
+ tempNum = calc.getMemory();
|
|
53
|
+ } else {
|
|
54
|
+ tempNum = Double.valueOf(tempString);
|
|
55
|
+ }
|
|
56
|
+ currentNum = calc.add(currentNum, tempNum);
|
|
57
|
+ break;
|
58
|
58
|
case '-': //takes string input. if statement places memory value into function, else converts to double
|
59
|
|
- tempString = Console.inputString();
|
60
|
|
- if(tempString.equals("R")){
|
61
|
|
- tempNum = calc.getMemory();
|
62
|
|
- } else {
|
63
|
|
- tempNum = Double.valueOf(tempString);
|
64
|
|
- }
|
65
|
|
- currentNum = calc.subtract(currentNum, tempNum);
|
66
|
|
- break;
|
|
59
|
+ tempString = Console.inputString();
|
|
60
|
+ if(tempString.equals("R")){
|
|
61
|
+ tempNum = calc.getMemory();
|
|
62
|
+ } else {
|
|
63
|
+ tempNum = Double.valueOf(tempString);
|
|
64
|
+ }
|
|
65
|
+ currentNum = calc.subtract(currentNum, tempNum);
|
|
66
|
+ break;
|
67
|
67
|
case '*': //takes string input. if statement places memory value into function, else converts to double
|
68
|
|
- tempString = Console.inputString();
|
69
|
|
- if(tempString.equals("R")){
|
70
|
|
- tempNum = calc.getMemory();
|
71
|
|
- } else {
|
72
|
|
- tempNum = Double.valueOf(tempString);
|
73
|
|
- }
|
74
|
|
- currentNum = calc.multiply(currentNum, tempNum);
|
75
|
|
- break;
|
|
68
|
+ tempString = Console.inputString();
|
|
69
|
+ if(tempString.equals("R")){
|
|
70
|
+ tempNum = calc.getMemory();
|
|
71
|
+ } else {
|
|
72
|
+ tempNum = Double.valueOf(tempString);
|
|
73
|
+ }
|
|
74
|
+ currentNum = calc.multiply(currentNum, tempNum);
|
|
75
|
+ break;
|
76
|
76
|
case '/': //takes string input. if statement places memory value into function, else converts to double
|
77
|
|
- tempString = Console.inputString();
|
78
|
|
- if(tempString.equals("R")){
|
79
|
|
- tempNum = calc.getMemory();
|
80
|
|
- } else {
|
81
|
|
- tempNum = Double.valueOf(tempString);
|
82
|
|
- }
|
83
|
|
- while(tempNum == 0 ){
|
84
|
|
- System.out.println("Error, cannot divide by zero. Please ");
|
85
|
|
- tempNum = Console.inputDouble();
|
86
|
|
- }
|
87
|
|
- currentNum = calc.divide(currentNum, tempNum);
|
88
|
|
- break;
|
|
77
|
+ tempString = Console.inputString();
|
|
78
|
+ if(tempString.equals("R")){
|
|
79
|
+ tempNum = calc.getMemory();
|
|
80
|
+ } else {
|
|
81
|
+ tempNum = Double.valueOf(tempString);
|
|
82
|
+ }
|
|
83
|
+ while(tempNum == 0 ){
|
|
84
|
+ System.out.print("Error, cannot divide by zero. Please ");
|
|
85
|
+ tempNum = Console.inputDouble();
|
|
86
|
+ }
|
|
87
|
+ currentNum = calc.divide(currentNum, tempNum);
|
|
88
|
+ break;
|
89
|
89
|
case '@':
|
90
|
|
- currentNum = calc.square(currentNum);
|
91
|
|
- break;
|
|
90
|
+ currentNum = calc.square(currentNum);
|
|
91
|
+ break;
|
92
|
92
|
case '&':
|
93
|
|
- currentNum = calc.squareRoot(currentNum);
|
94
|
|
- break;
|
|
93
|
+ currentNum = calc.squareRoot(currentNum);
|
|
94
|
+ break;
|
95
|
95
|
case '^': //takes string input. if statement places memory value into function, else converts to double
|
96
|
|
- tempString = Console.inputString();
|
97
|
|
- if(tempString.equals("R")){
|
98
|
|
- tempNum = calc.getMemory();
|
99
|
|
- } else {
|
100
|
|
- tempNum = Double.valueOf(tempString);
|
101
|
|
- }
|
102
|
|
- currentNum = calc.exponent(currentNum, tempNum);
|
103
|
|
- break;
|
|
96
|
+ tempString = Console.inputString();
|
|
97
|
+ if(tempString.equals("R")){
|
|
98
|
+ tempNum = calc.getMemory();
|
|
99
|
+ } else {
|
|
100
|
+ tempNum = Double.valueOf(tempString);
|
|
101
|
+ }
|
|
102
|
+ currentNum = calc.exponent(currentNum, tempNum);
|
|
103
|
+ break;
|
104
|
104
|
case '!':
|
105
|
|
- if (currentNum == 0){
|
106
|
|
- System.out.println("Error, cannot divide by zero. Press 'c' to clear.");
|
107
|
|
- continue;
|
108
|
|
- }
|
109
|
|
- currentNum = calc.invert(currentNum);
|
110
|
|
- break;
|
|
105
|
+ if (currentNum == 0){
|
|
106
|
+ System.out.println("Error, cannot divide by zero. Press 'c' to clear.");
|
|
107
|
+ continue;
|
|
108
|
+ }
|
|
109
|
+ currentNum = calc.invert(currentNum);
|
|
110
|
+ break;
|
111
|
111
|
case '#':
|
112
|
|
- currentNum = calc.changeSign(currentNum);
|
113
|
|
- break;
|
|
112
|
+ currentNum = calc.changeSign(currentNum);
|
|
113
|
+ break;
|
114
|
114
|
case 'M':
|
115
|
|
- calc.storeMemory(currentNum);
|
116
|
|
- Console.printMemoryValue(calc.getMemory());
|
117
|
|
- continue;
|
|
115
|
+ calc.storeMemory(currentNum);
|
|
116
|
+ Console.printMemoryValue(calc.getMemory());
|
|
117
|
+ continue;
|
118
|
118
|
case 'R':
|
119
|
|
- Console.printMemoryValue(calc.getMemory());
|
120
|
|
- break;
|
|
119
|
+ Console.printMemoryValue(calc.getMemory());
|
|
120
|
+ break;
|
121
|
121
|
case 'C':
|
122
|
|
- calc.clearMemory();
|
123
|
|
- Console.printMemoryValue(calc.getMemory());
|
124
|
|
- break;
|
|
122
|
+ calc.clearMemory();
|
|
123
|
+ Console.printMemoryValue(calc.getMemory());
|
|
124
|
+ break;
|
125
|
125
|
case '~':
|
126
|
|
- currentNum = Console.displayChange();
|
127
|
|
- break;
|
|
126
|
+ currentNum = Console.displayChange();
|
|
127
|
+ break;
|
128
|
128
|
case 'c':
|
129
|
|
- currentNum = Console.displayClear();
|
130
|
|
- currentNum = Double.valueOf(Console.inputString()); //asks for new value
|
131
|
|
- continue; //back to top of loop
|
|
129
|
+ currentNum = Console.displayClear();
|
|
130
|
+ currentNum = Double.valueOf(Console.inputString()); //asks for new value
|
|
131
|
+ continue; //back to top of loop
|
132
|
132
|
case 'l':
|
133
|
|
- Console.printLegend();
|
134
|
|
- break;
|
|
133
|
+ Console.printLegend();
|
|
134
|
+ break;
|
135
|
135
|
case 'q':
|
136
|
|
- Console.quit();
|
137
|
|
- break;
|
|
136
|
+ Console.quit();
|
|
137
|
+ break;
|
138
|
138
|
default:
|
139
|
|
- Console.errorOperator();
|
|
139
|
+ Console.errorOperator();
|
140
|
140
|
}
|
141
|
141
|
}
|
142
|
142
|
/**
|
|
@@ -157,8 +157,8 @@ public class MainApplication {
|
157
|
157
|
}
|
158
|
158
|
/*
|
159
|
159
|
if (Console.inputString() == "c"){
|
160
|
|
- Console.displayClear();
|
|
160
|
+ Console.displayClear();
|
161
|
161
|
}
|
162
|
|
- */
|
|
162
|
+ */
|
163
|
163
|
}
|
164
|
164
|
}
|