|
@@ -10,30 +10,21 @@ public class Main{
|
10
|
10
|
Calculator calc = new Calculator();
|
11
|
11
|
Memory memo = new Memory();
|
12
|
12
|
Display disp = new Display();
|
13
|
|
-
|
14
|
|
-
|
|
13
|
+
|
15
|
14
|
//User input
|
16
|
15
|
Scanner reader = new Scanner(System.in);
|
17
|
16
|
Console.println("Welcome to Calculator!");
|
18
|
17
|
double value = 0;
|
19
|
18
|
double saveValue = 0;
|
20
|
|
-
|
|
19
|
+
|
21
|
20
|
while(true){
|
22
|
|
- Console.println("Pick Operation: Clear (-) OFF");
|
23
|
|
- Console.println(" Sq SqRt ! ^");
|
24
|
|
- Console.println(" + - * /");
|
25
|
|
- Console.println(" Cos Sin Tan");
|
26
|
|
- Console.println(" -Cos -Sin -Tan");
|
27
|
|
- Console.println(" log -log ln");
|
28
|
|
- Console.println(" M+ MC MRC");
|
29
|
|
- Console.println(" Deg Round %");
|
30
|
|
- Console.println(" Display Mode");
|
|
21
|
+ Console.println("Pick Operation: Clear (-) OFF\n Sq SqRt ! ^\n + - * /");
|
|
22
|
+ Console.println(" Cos Sin Tan\n -Cos -Sin -Tan\n log -log ln");
|
|
23
|
+ Console.println(" M+ MC MRC\n Deg Round %\n Display Mode");
|
31
|
24
|
String button = reader.nextLine();
|
32
|
|
-
|
|
25
|
+
|
33
|
26
|
double x = saveValue;
|
34
|
|
- int z = 0;
|
35
|
|
-
|
36
|
|
-
|
|
27
|
+
|
37
|
28
|
List<String> button1 = Arrays.asList("(-)", "Sq", "SqRt", "Cos", "Sin", "Tan", "-Cos", "-Sin", "-Tan");
|
38
|
29
|
List<String> button2 = Arrays.asList("Bin", "Oct", "Hex", "Dec");
|
39
|
30
|
|
|
@@ -52,166 +43,166 @@ public class Main{
|
52
|
43
|
Console.println(memo.recallNumber(saveValue));
|
53
|
44
|
continue;
|
54
|
45
|
}
|
55
|
|
-
|
|
46
|
+
|
56
|
47
|
if(button1.contains(button)){
|
57
|
48
|
switch(button){
|
58
|
49
|
case "(-)":
|
59
|
|
- value = calc.invert(x);
|
60
|
|
- saveValue = value;
|
61
|
|
- Console.println(Double.toString(value));
|
62
|
|
- break;
|
|
50
|
+ value = calc.invert(x);
|
|
51
|
+ saveValue = value;
|
|
52
|
+ Console.println(Double.toString(value));
|
|
53
|
+ break;
|
63
|
54
|
case "Sq":
|
64
|
|
- value = calc.square(x);
|
65
|
|
- saveValue = value;
|
66
|
|
- Console.println(Double.toString(value));
|
67
|
|
- break;
|
|
55
|
+ value = calc.square(x);
|
|
56
|
+ saveValue = value;
|
|
57
|
+ Console.println(Double.toString(value));
|
|
58
|
+ break;
|
68
|
59
|
case "SqRt":
|
69
|
|
- value = calc.squareRoot(x);
|
70
|
|
- saveValue = value;
|
71
|
|
- Console.println(Double.toString(value));
|
72
|
|
- break;
|
|
60
|
+ value = calc.squareRoot(x);
|
|
61
|
+ saveValue = value;
|
|
62
|
+ Console.println(Double.toString(value));
|
|
63
|
+ break;
|
73
|
64
|
case "Cos":
|
74
|
|
- value = calc.getCosine(x);
|
75
|
|
- saveValue = value;
|
76
|
|
- Console.println(Double.toString(value));
|
77
|
|
- break;
|
|
65
|
+ value = calc.getCosine(x);
|
|
66
|
+ saveValue = value;
|
|
67
|
+ Console.println(Double.toString(value));
|
|
68
|
+ break;
|
78
|
69
|
case "Sin":
|
79
|
|
- value = calc.getSine(x);
|
80
|
|
- saveValue = value;
|
81
|
|
- Console.println(Double.toString(value));
|
82
|
|
- break;
|
|
70
|
+ value = calc.getSine(x);
|
|
71
|
+ saveValue = value;
|
|
72
|
+ Console.println(Double.toString(value));
|
|
73
|
+ break;
|
83
|
74
|
case "Tan":
|
84
|
|
- value = calc.getTan(x);
|
85
|
|
- saveValue = value;
|
86
|
|
- Console.println(Double.toString(value));
|
87
|
|
- break;
|
|
75
|
+ value = calc.getTan(x);
|
|
76
|
+ saveValue = value;
|
|
77
|
+ Console.println(Double.toString(value));
|
|
78
|
+ break;
|
88
|
79
|
case "-Cos":
|
89
|
|
- value = calc.inverseCos(x);
|
90
|
|
- saveValue = value;
|
91
|
|
- Console.println(Double.toString(value));
|
92
|
|
- break;
|
|
80
|
+ value = calc.inverseCos(x);
|
|
81
|
+ saveValue = value;
|
|
82
|
+ Console.println(Double.toString(value));
|
|
83
|
+ break;
|
93
|
84
|
case "-Sin":
|
94
|
|
- value = calc.inverseSin(x);
|
95
|
|
- saveValue = value;
|
96
|
|
- Console.println(Double.toString(value));
|
97
|
|
- break;
|
|
85
|
+ value = calc.inverseSin(x);
|
|
86
|
+ saveValue = value;
|
|
87
|
+ Console.println(Double.toString(value));
|
|
88
|
+ break;
|
98
|
89
|
case "-Tan":
|
99
|
|
- value = calc.inverseTan(x);
|
100
|
|
- saveValue = value;
|
101
|
|
- Console.println(Double.toString(value));
|
102
|
|
- break;
|
|
90
|
+ value = calc.inverseTan(x);
|
|
91
|
+ saveValue = value;
|
|
92
|
+ Console.println(Double.toString(value));
|
|
93
|
+ break;
|
103
|
94
|
case "!":
|
104
|
|
- value = calc.factorial(x);
|
105
|
|
- saveValue = value;
|
106
|
|
- Console.println(Double.toString(value));
|
107
|
|
- break;
|
|
95
|
+ value = calc.factorial(x);
|
|
96
|
+ saveValue = value;
|
|
97
|
+ Console.println(Double.toString(value));
|
|
98
|
+ break;
|
108
|
99
|
case "log":
|
109
|
|
- value = calc.log(x);
|
110
|
|
- saveValue = value;
|
111
|
|
- Console.println(Double.toString(value));
|
112
|
|
- break;
|
|
100
|
+ value = calc.log(x);
|
|
101
|
+ saveValue = value;
|
|
102
|
+ Console.println(Double.toString(value));
|
|
103
|
+ break;
|
113
|
104
|
case "-log":
|
114
|
|
- value = calc.inverseLog(x);
|
115
|
|
- saveValue = value;
|
116
|
|
- Console.println(Double.toString(value));
|
117
|
|
- break;
|
|
105
|
+ value = calc.inverseLog(x);
|
|
106
|
+ saveValue = value;
|
|
107
|
+ Console.println(Double.toString(value));
|
|
108
|
+ break;
|
118
|
109
|
case "ln":
|
119
|
|
- value = calc.natLog(x);
|
120
|
|
- saveValue = value;
|
121
|
|
- Console.println(Double.toString(value));
|
122
|
|
- break;
|
|
110
|
+ value = calc.natLog(x);
|
|
111
|
+ saveValue = value;
|
|
112
|
+ Console.println(Double.toString(value));
|
|
113
|
+ break;
|
123
|
114
|
case "Round":
|
124
|
|
- value = calc.round(x);
|
125
|
|
- saveValue = value;
|
126
|
|
- Console.println(Double.toString(value));
|
127
|
|
- break;
|
|
115
|
+ value = calc.round(x);
|
|
116
|
+ saveValue = value;
|
|
117
|
+ Console.println(Double.toString(value));
|
|
118
|
+ break;
|
128
|
119
|
case "Deg":
|
129
|
|
- value = disp.makeDegree(x);
|
130
|
|
- saveValue = value;
|
131
|
|
- Console.println(Double.toString(value));
|
132
|
|
- break;
|
133
|
|
- case "%":
|
134
|
|
- value = disp.convertPercent(x);
|
135
|
|
- saveValue = value;
|
136
|
|
- Console.println(Double.toString(value));
|
137
|
|
- break;
|
138
|
|
- case "Display Mode":
|
139
|
|
- if(button2.contains(button)){
|
140
|
|
-
|
141
|
|
- Console.println("Binary Octal Hexadecimal Decimal");
|
142
|
|
-
|
143
|
|
- switch(button){
|
144
|
|
- case "Binary":
|
145
|
|
- value = disp.toBinary(z);
|
146
|
|
- Console.println("Binary: ", Double.toString(value));
|
147
|
|
- case "Octal":
|
148
|
|
- value = disp.toOctal(z);
|
149
|
|
- Console.println("Octal: ", Double.toString(value));
|
150
|
|
- case "Hexadecimal":
|
151
|
|
- value = disp.toHexadecimal(z);
|
152
|
|
- Console.println("Hexadecimal: ", Double.toString(value));
|
153
|
|
- case "Decimal":
|
154
|
|
- value = disp.decimal(x);
|
155
|
|
- }
|
156
|
|
- }else{
|
|
120
|
+ value = disp.makeDegree(x);
|
|
121
|
+ saveValue = value;
|
|
122
|
+ Console.println(Double.toString(value));
|
157
|
123
|
break;
|
158
|
|
- }
|
|
124
|
+ case "%":
|
|
125
|
+ value = disp.convertPercent(x);
|
|
126
|
+ saveValue = value;
|
|
127
|
+ Console.println(Double.toString(value));
|
|
128
|
+ break;
|
|
129
|
+
|
159
|
130
|
}
|
160
|
131
|
}
|
161
|
|
-
|
162
|
|
- else{
|
163
|
132
|
|
|
133
|
+ else{
|
164
|
134
|
double y = Console.getDoubleInput("Input Number:");
|
165
|
|
-
|
166
|
135
|
switch(button){
|
167
|
136
|
case "+":
|
168
|
|
- value = calc.add(x, y);
|
169
|
|
- saveValue = value;
|
170
|
|
- Console.println(Double.toString(value));
|
171
|
|
- break;
|
|
137
|
+ value = calc.add(x, y);
|
|
138
|
+ saveValue = value;
|
|
139
|
+ Console.println(Double.toString(value));
|
|
140
|
+ break;
|
172
|
141
|
case "-":
|
173
|
|
- value = calc.subtract(x, y);
|
174
|
|
- saveValue = value;
|
175
|
|
- Console.println(Double.toString(value));
|
176
|
|
- break;
|
|
142
|
+ value = calc.subtract(x, y);
|
|
143
|
+ saveValue = value;
|
|
144
|
+ Console.println(Double.toString(value));
|
|
145
|
+ break;
|
177
|
146
|
case "*":
|
178
|
|
- value = calc.multiply(x, y);
|
179
|
|
- saveValue = value;
|
180
|
|
- Console.println(Double.toString(value));
|
181
|
|
- break;
|
|
147
|
+ value = calc.multiply(x, y);
|
|
148
|
+ saveValue = value;
|
|
149
|
+ Console.println(Double.toString(value));
|
|
150
|
+ break;
|
182
|
151
|
case "/":
|
183
|
|
- value = calc.divide(x, y);
|
184
|
|
- saveValue = value;
|
185
|
|
- Console.println(Double.toString(value));
|
186
|
|
- break;
|
|
152
|
+ value = calc.divide(x, y);
|
|
153
|
+ saveValue = value;
|
|
154
|
+ Console.println(Double.toString(value));
|
|
155
|
+ break;
|
187
|
156
|
case "^":
|
188
|
|
- value = calc.getPow(x, y);
|
189
|
|
- saveValue = value;
|
190
|
|
- Console.println(Double.toString(value));
|
191
|
|
- break;
|
|
157
|
+ value = calc.getPow(x, y);
|
|
158
|
+ saveValue = value;
|
|
159
|
+ Console.println(Double.toString(value));
|
|
160
|
+ break;
|
192
|
161
|
default:
|
193
|
|
- Console.print("Err");
|
194
|
|
- break;
|
|
162
|
+ Console.print("Err");
|
|
163
|
+ break;
|
195
|
164
|
}
|
196
|
165
|
}
|
197
|
166
|
|
198
|
167
|
switch(button){
|
199
|
|
- case "Clear":
|
|
168
|
+ case "Display Mode":
|
|
169
|
+ if(button2.contains(button)){
|
|
170
|
+ int z = 0;
|
|
171
|
+ Console.println("Binary Octal Hexadecimal Decimal");
|
|
172
|
+ switch(button){
|
|
173
|
+ case "Binary":
|
|
174
|
+ value = disp.toBinary(z);
|
|
175
|
+ Console.println("Binary: ", Double.toString(value));
|
|
176
|
+ case "Octal":
|
|
177
|
+ value = disp.toOctal(z);
|
|
178
|
+ Console.println("Octal: ", Double.toString(value));
|
|
179
|
+ case "Hexadecimal":
|
|
180
|
+ value = disp.toHexadecimal(z);
|
|
181
|
+ Console.println("Hexadecimal: ", Double.toString(value));
|
|
182
|
+ case "Decimal":
|
|
183
|
+ value = disp.decimal(x);
|
|
184
|
+ }
|
|
185
|
+ }else{
|
|
186
|
+ break;
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ switch(button){
|
|
190
|
+ case "Clear":
|
200
|
191
|
value = 0;
|
201
|
192
|
break;
|
202
|
|
- case "M+":
|
|
193
|
+ case "M+":
|
203
|
194
|
memo.saveNumber(saveValue);
|
204
|
195
|
break;
|
205
|
|
- case "MC":
|
|
196
|
+ case "MC":
|
206
|
197
|
memo.eraseNumber(saveValue);
|
207
|
198
|
break;
|
208
|
|
- case "MRC":
|
|
199
|
+ case "MRC":
|
209
|
200
|
memo.recallNumber(saveValue);
|
210
|
201
|
break;
|
211
|
|
- case "OFF":
|
|
202
|
+ case "OFF":
|
212
|
203
|
return;
|
213
|
|
- }
|
214
|
|
- }
|
|
204
|
+ }
|
|
205
|
+ }
|
|
206
|
+ }
|
215
|
207
|
}
|
216
|
208
|
}
|
217
|
|
-
|