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