-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.java
238 lines (170 loc) · 5.9 KB
/
Calculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import java.util.Scanner;
import java.lang.Math;
class Main{
public static void main(String[]args){
home();
}
static void home(){
double section;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("WELCOME TO SPENCER'S CALCULATOR");
System.out.println();
System.out.println("Please choose the operation you would like to do by typing what is in the []'s:");
System.out.println();
System.out.println("[1]'Add, subtract, multiply, divide'");
System.out.println("[2]'Square Root'");
System.out.println("[3]'Exponents'");
System.out.println("--------------------------------------------------");
System.out.println();
Scanner op = new Scanner(System.in);
section = op.nextDouble();
if (section == 1){
basic();
}
else if (section == 2){
sqroot();
}
else if (section == 3){
exponent();
}
}
static void basic(){
double operation;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Would you like to: ");
System.out.println("[1] 'ADD'");
System.out.println("[2] 'SUBTRACT' ");
System.out.println("[3] 'MULTIPLY'");
System.out.println("[4] 'DIVIDE'");
System.out.println("[5] 'Home'");
System.out.println("--------------------------------------------------");
System.out.println();
Scanner operation1 = new Scanner(System.in);
operation = operation1.nextDouble();
if (operation == 1){
add();
}
else if (operation == 2){
subtract();
}
else if (operation == 3){
multiply();
}
else if (operation == 4){
divide();
}
else if (operation == 5){
home();
}
else{
System.out.println("ERROR INVALID INPUT");
basic();
}
}
static void add(){
double first;
double second;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the first number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
System.out.println("Please enter the second number:");
Scanner second1 = new Scanner(System.in);
second = second1.nextDouble();
answer = first + second;
System.out.println(first + " + " + second + " = " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
basic();
}
static void subtract(){
double first;
double second;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the first number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
System.out.println("Please enter the second number:");
Scanner second1 = new Scanner(System.in);
second = second1.nextDouble();
answer = first - second;
System.out.println(first + " - " + second + " = " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
basic();
}
static void multiply(){
double first;
double second;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the first number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
System.out.println("Please enter the second number:");
Scanner second1 = new Scanner(System.in);
second = second1.nextDouble();
answer = first * second;
System.out.println(first + " x " + second + " = " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
basic();
}
static void divide(){
double first;
double second;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the first number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
System.out.println("Please enter the second number:");
Scanner second1 = new Scanner(System.in);
second = second1.nextDouble();
answer = first / second;
System.out.println(first + " / " + second + " = " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
basic();
}
static void sqroot(){
double first;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
answer = Math.sqrt(first);
System.out.println("The Square Root of " + first + " is " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
home();
}
static void exponent(){
double first;
double second;
double answer;
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Please enter the number:");
Scanner first1 = new Scanner(System.in);
first = first1.nextDouble();
System.out.println("Please enter the exponent:");
Scanner second1 = new Scanner(System.in);
second = second1.nextDouble();
answer = Math.pow(first, second);
System.out.println(first + " ^ " + second + " = " + answer);
System.out.println("--------------------------------------------------");
System.out.println("Enter another operation:");
home();
}
}