|
@@ -0,0 +1,260 @@
|
|
1
|
+
|
|
2
|
+/**
|
|
3
|
+ * Write a description of class Cal here.
|
|
4
|
+ *
|
|
5
|
+ * @author (your name)
|
|
6
|
+ * @version (a version number or a date)
|
|
7
|
+ */
|
|
8
|
+import java.io.IOException;
|
|
9
|
+import java.util.Scanner;
|
|
10
|
+import java.util.*;
|
|
11
|
+public class Cal{
|
|
12
|
+ public static void main (String[]args){
|
|
13
|
+ // instance variables - replace the example below with your own
|
|
14
|
+ Scanner scan = new Scanner(System.in);
|
|
15
|
+ double calcValue1;
|
|
16
|
+ double calcValue2;
|
|
17
|
+ double addTwoNumbers;
|
|
18
|
+ double getCalcValue;
|
|
19
|
+ int options = 0;
|
|
20
|
+
|
|
21
|
+ double answer;
|
|
22
|
+ double sum;
|
|
23
|
+ boolean off = false;
|
|
24
|
+ boolean on = true;
|
|
25
|
+ int num1 =0;
|
|
26
|
+ int num2 =0;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ System.out.print("Let's crunch some numbers");
|
|
30
|
+ while (on){
|
|
31
|
+
|
|
32
|
+ System.out.println("Please enter the number of what you want to do");
|
|
33
|
+ System.out.println("1. Add ");
|
|
34
|
+ System.out.println("2. Substract");
|
|
35
|
+ System.out.println("3. Multiply ");
|
|
36
|
+ System.out.println("4. Division");
|
|
37
|
+ System.out.println("5. Modulus ");
|
|
38
|
+ System.out.println("6. Square Root");
|
|
39
|
+ System.out.println("7. Avg");
|
|
40
|
+ System.out.println("8. Exp");
|
|
41
|
+ System.out.println("9. Mode");
|
|
42
|
+ System.out.println("10. Max");
|
|
43
|
+ System.out.println("11. Min");
|
|
44
|
+ System.out.println("12. Abs");
|
|
45
|
+ System.out.println("13. Round");
|
|
46
|
+ System.out.println("14. Sin");
|
|
47
|
+ System.out.println("15. Cos");
|
|
48
|
+ System.out.println("16. tan");
|
|
49
|
+ System.out.println("17. Quit");
|
|
50
|
+ scan.hasNextInt();
|
|
51
|
+ options = scan.nextInt();
|
|
52
|
+
|
|
53
|
+ try{
|
|
54
|
+
|
|
55
|
+ switch (options){
|
|
56
|
+
|
|
57
|
+ case 1: //Sum
|
|
58
|
+ //System.out.print('\u000C');
|
|
59
|
+
|
|
60
|
+ System.out.println("Enter Number1 ");
|
|
61
|
+ num1= scan.nextInt();
|
|
62
|
+
|
|
63
|
+ System.out.println("Enter Number2 ");
|
|
64
|
+ num2 = scan.nextInt();
|
|
65
|
+
|
|
66
|
+ answer=Math_methods.add(num1,num2);
|
|
67
|
+ System.out.println(answer);
|
|
68
|
+ break;
|
|
69
|
+
|
|
70
|
+ case 2: //difference:
|
|
71
|
+ //System.out.print('\u000C');
|
|
72
|
+ System.out.println("Enter Number1 ");
|
|
73
|
+ num1= scan.nextInt();
|
|
74
|
+
|
|
75
|
+ System.out.println("Enter Number2 ");
|
|
76
|
+ num2 = scan.nextInt();
|
|
77
|
+ answer = Math_methods.minus(num1,num2);
|
|
78
|
+ System.out.println(answer);
|
|
79
|
+ break;
|
|
80
|
+
|
|
81
|
+ case 3: // multiply:
|
|
82
|
+ //System.out.print('\u000C');
|
|
83
|
+ System.out.println("Enter Number1 ");
|
|
84
|
+ num1= scan.nextInt();
|
|
85
|
+
|
|
86
|
+ System.out.println("Enter Number2 ");
|
|
87
|
+ num2 = scan.nextInt();
|
|
88
|
+ answer = Math_methods.mult(num1,num2);
|
|
89
|
+ System.out.println(answer);
|
|
90
|
+ break;
|
|
91
|
+
|
|
92
|
+ case 4: //divide:
|
|
93
|
+ //System.out.print('\u000C');
|
|
94
|
+ System.out.println("Enter Number1 ");
|
|
95
|
+ num1= scan.nextInt();
|
|
96
|
+
|
|
97
|
+ System.out.println("Enter Number2 ");
|
|
98
|
+ num2 = scan.nextInt();
|
|
99
|
+ answer = Math_methods.div(num1,num2);
|
|
100
|
+ System.out.println(answer);
|
|
101
|
+ break;
|
|
102
|
+
|
|
103
|
+ case 5: //modulus:
|
|
104
|
+ //System.out.print('\u000C');
|
|
105
|
+ System.out.println("Enter Number1 ");
|
|
106
|
+ num1= scan.nextInt();
|
|
107
|
+
|
|
108
|
+ System.out.println("Enter Number2 ");
|
|
109
|
+ num2 = scan.nextInt();
|
|
110
|
+ answer = Math_methods.mod(num1,num2);
|
|
111
|
+ System.out.println(answer);
|
|
112
|
+ break;
|
|
113
|
+
|
|
114
|
+ case 6: //squareRoot:
|
|
115
|
+ //System.out.print('\u000C');
|
|
116
|
+ System.out.println("Enter Number1 ");
|
|
117
|
+ num1= scan.nextInt();
|
|
118
|
+
|
|
119
|
+ answer = Math_methods.sqrt(num1);
|
|
120
|
+ System.out.println("Enter Number2 ");
|
|
121
|
+ num2 = scan.nextInt();
|
|
122
|
+ answer = Math_methods.sqrt(num1);
|
|
123
|
+
|
|
124
|
+ System.out.println(answer);
|
|
125
|
+ break;
|
|
126
|
+
|
|
127
|
+ case 7: //Average:
|
|
128
|
+ //System.out.print('\u000C');
|
|
129
|
+ System.out.println("Enter Number1 ");
|
|
130
|
+ num1= scan.nextInt();
|
|
131
|
+
|
|
132
|
+ System.out.println("Enter Number2 ");
|
|
133
|
+ num2 = scan.nextInt();
|
|
134
|
+ answer = Math_methods.ave(num1,num2);
|
|
135
|
+ System.out.println(answer);
|
|
136
|
+ break;
|
|
137
|
+
|
|
138
|
+ case 8: //Exponent:
|
|
139
|
+ //System.out.print('\u000C');
|
|
140
|
+ System.out.println("Enter Number1 ");
|
|
141
|
+ num1= scan.nextInt();
|
|
142
|
+
|
|
143
|
+ System.out.println("Enter Number2 ");
|
|
144
|
+ num2 = scan.nextInt();
|
|
145
|
+ answer = Math_methods.exp(num1,num2);
|
|
146
|
+ System.out.println(answer);
|
|
147
|
+ break;
|
|
148
|
+
|
|
149
|
+ case 9: //Mod:
|
|
150
|
+ //System.out.print('\u000C');
|
|
151
|
+ System.out.println("Enter Number1 ");
|
|
152
|
+ num1= scan.nextInt();
|
|
153
|
+
|
|
154
|
+ System.out.println("Enter Number2 ");
|
|
155
|
+ num2 = scan.nextInt();
|
|
156
|
+ answer = Math_methods.mod(num1,num2);
|
|
157
|
+ System.out.println(answer);
|
|
158
|
+ break;
|
|
159
|
+
|
|
160
|
+ case 10:
|
|
161
|
+ System.out.println("Enter Number1 ");
|
|
162
|
+ num1= scan.nextInt();
|
|
163
|
+
|
|
164
|
+ System.out.println("Enter Number2 ");
|
|
165
|
+ num2 = scan.nextInt();
|
|
166
|
+ answer = Math_methods.max(num1,num2);
|
|
167
|
+ System.out.println(answer);
|
|
168
|
+ break;
|
|
169
|
+
|
|
170
|
+ case 11: //Minimum:
|
|
171
|
+
|
|
172
|
+ System.out.println("Enter Number1 ");
|
|
173
|
+ num1= scan.nextInt();
|
|
174
|
+
|
|
175
|
+ System.out.println("Enter Number2 ");
|
|
176
|
+ num2 = scan.nextInt();
|
|
177
|
+ answer = Math_methods.min(num1,num2);
|
|
178
|
+ System.out.println(answer);
|
|
179
|
+ break;
|
|
180
|
+
|
|
181
|
+ case 12: //Absolute value:
|
|
182
|
+ //System.out.print('\u000C');
|
|
183
|
+ System.out.println("Enter Number1 ");
|
|
184
|
+ num1= scan.nextInt();
|
|
185
|
+
|
|
186
|
+ answer = Math_methods.abs(num1);
|
|
187
|
+ System.out.println(answer);
|
|
188
|
+ break;
|
|
189
|
+
|
|
190
|
+ case 13:
|
|
191
|
+ System.out.println("Enter Number1 ");
|
|
192
|
+ num1= scan.nextInt();
|
|
193
|
+
|
|
194
|
+ answer = Math_methods.round(num1);
|
|
195
|
+ System.out.println(answer);
|
|
196
|
+ break;
|
|
197
|
+
|
|
198
|
+ case 14:
|
|
199
|
+ System.out.println("Enter Number1 ");
|
|
200
|
+ num1= scan.nextInt();
|
|
201
|
+
|
|
202
|
+ answer = Math_methods.sin(num1);
|
|
203
|
+ System.out.println(answer);
|
|
204
|
+ break;
|
|
205
|
+
|
|
206
|
+ case 15:
|
|
207
|
+ System.out.println("Enter Number1 ");
|
|
208
|
+ num1= scan.nextInt();
|
|
209
|
+
|
|
210
|
+ answer = Math_methods.cos(num1);
|
|
211
|
+ System.out.println(answer);
|
|
212
|
+ break;
|
|
213
|
+
|
|
214
|
+ case 16:
|
|
215
|
+ System.out.println("Enter Number1 ");
|
|
216
|
+ num1= scan.nextInt();
|
|
217
|
+
|
|
218
|
+ answer = Math_methods.tan(num1);
|
|
219
|
+ System.out.println(answer);
|
|
220
|
+ break;
|
|
221
|
+
|
|
222
|
+ case 17:
|
|
223
|
+ System.exit(0);
|
|
224
|
+ break;
|
|
225
|
+
|
|
226
|
+ default:
|
|
227
|
+ System.out.println("Hello");
|
|
228
|
+ System.out.print('\u000C');
|
|
229
|
+
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ }
|
|
233
|
+ catch(NumberFormatException e){
|
|
234
|
+ //catch(Exception e){
|
|
235
|
+ System.out.printf("Wrong number or not enough numbers");
|
|
236
|
+
|
|
237
|
+ }
|
|
238
|
+ /* while(options == 0){
|
|
239
|
+ break;
|
|
240
|
+ }*/
|
|
241
|
+ }
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ /*catch(IOException e){
|
|
245
|
+ System.out.println(error);
|
|
246
|
+ abc.displayErrorMessage("Please Enter 2 digit");
|
|
247
|
+ }
|
|
248
|
+ /*
|
|
249
|
+ public void addNum2(int Number1, int Number2){
|
|
250
|
+
|
|
251
|
+ calcValue1 = Number1 + Number2;
|
|
252
|
+
|
|
253
|
+ }
|
|
254
|
+
|
|
255
|
+ public int getCalcValue(){
|
|
256
|
+
|
|
257
|
+ return calculationValue;
|
|
258
|
+ */
|
|
259
|
+
|
|
260
|
+}
|