|
@@ -13,20 +13,23 @@ public double chooseOp(double num){
|
13
|
13
|
double result = -1;
|
14
|
14
|
|
15
|
15
|
while(!isValid){
|
|
16
|
+ System.out.println("\n-------------------------------------------------");
|
16
|
17
|
System.out.println("Select type of operation to perform (enter # 1-3)");
|
17
|
18
|
System.out.println("(1) Core Functions");
|
18
|
19
|
System.out.println("(2) Trigonometry");
|
19
|
20
|
System.out.println("(3) Advanced Functions");
|
|
21
|
+ System.out.println("-------------------------------------------------");
|
|
22
|
+ System.out.print("> ");
|
20
|
23
|
choice = stdin.nextInt();
|
21
|
24
|
|
22
|
25
|
switch(choice){
|
23
|
26
|
case 1: result = coreFunc(num);
|
24
|
27
|
isValid = true;
|
25
|
28
|
break;
|
26
|
|
- case 2:trigFunc();
|
|
29
|
+ case 2: result = trigFunc(num);
|
27
|
30
|
isValid = true;
|
28
|
31
|
break;
|
29
|
|
- case 3:advFunc();
|
|
32
|
+ case 3: result = advFunc(num);
|
30
|
33
|
isValid = true;
|
31
|
34
|
break;
|
32
|
35
|
default:
|
|
@@ -40,11 +43,12 @@ public double coreFunc(double num){ //take displayNum as input parameter
|
40
|
43
|
|
41
|
44
|
boolean isValid = false;
|
42
|
45
|
int choice;
|
43
|
|
- double entNum, result = -1;
|
|
46
|
+ double entNum, result = 0;
|
44
|
47
|
|
45
|
48
|
|
46
|
49
|
while(!isValid){
|
47
|
|
- System.out.println("Select core function to perform (enter # 1-3)");
|
|
50
|
+ System.out.println("\n---------------------------------------------");
|
|
51
|
+ System.out.println("Select core function to perform (enter # 1-9)");
|
48
|
52
|
System.out.println("(1) Add");
|
49
|
53
|
System.out.println("(2) Subtract");
|
50
|
54
|
System.out.println("(3) Multiply");
|
|
@@ -54,6 +58,8 @@ public double coreFunc(double num){ //take displayNum as input parameter
|
54
|
58
|
System.out.println("(7) Exponentiation");
|
55
|
59
|
System.out.println("(8) Inverse (1/x)");
|
56
|
60
|
System.out.println("(9) Change sign (+/-)");
|
|
61
|
+ System.out.println("---------------------------------------------");
|
|
62
|
+ System.out.print("> ");
|
57
|
63
|
choice = stdin.nextInt();
|
58
|
64
|
|
59
|
65
|
switch(choice){
|
|
@@ -71,125 +77,151 @@ public double coreFunc(double num){ //take displayNum as input parameter
|
71
|
77
|
entNum = stdin.nextDouble();
|
72
|
78
|
result = num * entNum;
|
73
|
79
|
isValid = true;
|
74
|
|
- break;
|
|
80
|
+ break;
|
75
|
81
|
case 4: System.out.println("Enter number to divide from " + num + ": ");
|
76
|
82
|
entNum = stdin.nextDouble();
|
77
|
83
|
result = num / entNum; //use Double.isNaN(x)
|
78
|
84
|
isValid = true;
|
79
|
|
- break;
|
80
|
|
- case 5:
|
|
85
|
+ break;
|
|
86
|
+ case 5: System.out.println("Squaring number on display (" + num + "^2) ");
|
|
87
|
+ result = num * num;
|
81
|
88
|
isValid = true;
|
82
|
|
- break;
|
83
|
|
- case 6:
|
|
89
|
+ break;
|
|
90
|
+ case 6: System.out.println("Taking square root of " + num);//cant take negative #
|
|
91
|
+ result = Math.sqrt(num);
|
84
|
92
|
isValid = true;
|
85
|
|
- break;
|
86
|
|
- case 7:
|
|
93
|
+ break;
|
|
94
|
+ case 7: System.out.println("Enter exponent to raise " + num + " to (" + num + "^n)");
|
|
95
|
+ entNum = stdin.nextDouble();
|
|
96
|
+ result = num * entNum;
|
87
|
97
|
isValid = true;
|
88
|
|
- break;
|
89
|
|
- case 8:
|
|
98
|
+ break;
|
|
99
|
+ case 8: System.out.println("Calculating inverse of " + num + " (1/" + num + ")");
|
|
100
|
+ result = 1/num;
|
90
|
101
|
isValid = true;
|
91
|
|
- break;
|
92
|
|
- case 9:
|
|
102
|
+ break;
|
|
103
|
+ case 9: System.out.println("Calculating negation of " + num + " (n -> -n , -n -> n)");
|
|
104
|
+ result = num * -1;
|
93
|
105
|
isValid = true;
|
94
|
|
- break;
|
|
106
|
+ break;
|
95
|
107
|
default:
|
96
|
|
- break;
|
|
108
|
+ break;
|
97
|
109
|
}
|
98
|
110
|
}
|
99
|
111
|
return result;
|
100
|
112
|
}
|
101
|
113
|
|
102
|
114
|
|
103
|
|
-public double trigFunc(){ //take displayNum as input parameter
|
|
115
|
+public double trigFunc(double num){ //take displayNum as input parameter
|
104
|
116
|
|
105
|
117
|
boolean isValid = false;
|
106
|
118
|
int choice;
|
107
|
|
- double result = -1;
|
|
119
|
+ double result = -0;
|
108
|
120
|
|
109
|
121
|
while(!isValid){
|
110
|
|
- System.out.println("Select trigonemtric function to perform (enter # 1-3)");
|
|
122
|
+ System.out.println("\n--------------------------------------------");
|
|
123
|
+ System.out.println("Select trigonemtric function (enter # 1-6)");
|
111
|
124
|
System.out.println("(1) Sin");
|
112
|
125
|
System.out.println("(2) Cos");
|
113
|
126
|
System.out.println("(3) Tangent");
|
114
|
127
|
System.out.println("(4) ArcSin");
|
115
|
128
|
System.out.println("(5) ArcCos");
|
116
|
129
|
System.out.println("(6) ArcTan");
|
|
130
|
+ System.out.println("--------------------------------------------");
|
|
131
|
+ System.out.print("> ");
|
117
|
132
|
choice = stdin.nextInt();
|
118
|
133
|
|
119
|
134
|
switch(choice){
|
120
|
|
- case 1:
|
|
135
|
+ case 1: System.out.println("Calculating sine of " + num);
|
|
136
|
+ result = Math.sin(num);
|
121
|
137
|
isValid = true;
|
122
|
138
|
break;
|
123
|
|
- case 2:
|
|
139
|
+ case 2: System.out.println("Calculating cosine of " + num);
|
|
140
|
+ result = Math.cos(num);
|
124
|
141
|
isValid = true;
|
125
|
142
|
break;
|
126
|
|
- case 3:
|
|
143
|
+ case 3: System.out.println("Calculating tangent of " + num);
|
|
144
|
+ result = Math.tan(num);
|
127
|
145
|
isValid = true;
|
128
|
146
|
break;
|
129
|
|
- case 4:
|
|
147
|
+ case 4: System.out.println("Calculating inverse sine (arcSin) of " + num);
|
|
148
|
+ result = Math.asin(num);
|
130
|
149
|
isValid = true;
|
131
|
150
|
break;
|
132
|
|
- case 5:
|
|
151
|
+ case 5: System.out.println("Calculating inverse cosine (arcCos) of " + num);
|
|
152
|
+ result = Math.acos(num);
|
133
|
153
|
isValid = true;
|
134
|
154
|
break;
|
135
|
|
- case 6:
|
|
155
|
+ case 6: System.out.println("Calculating inverse tangent (arcTan) of " + num);
|
|
156
|
+ result = Math.atan(num);
|
136
|
157
|
isValid = true;
|
137
|
158
|
break;
|
138
|
159
|
|
139
|
160
|
}
|
140
|
161
|
}
|
141
|
|
- return 2;
|
|
162
|
+ return result;
|
142
|
163
|
}
|
143
|
164
|
|
144
|
|
-public double advFunc(){ //take displayNum as input parameter
|
|
165
|
+public double advFunc(double num){ //take displayNum as input parameter
|
145
|
166
|
|
146
|
167
|
boolean isValid = false;
|
147
|
168
|
int choice;
|
|
169
|
+ double result = 0;
|
148
|
170
|
|
149
|
171
|
while(!isValid){
|
150
|
|
- System.out.println("Select advanced function to perform (enter # 1-3)");
|
|
172
|
+ System.out.println("\n-------------------------------------------------");
|
|
173
|
+ System.out.println("Select advanced function to perform (enter # 1-7)");
|
151
|
174
|
System.out.println("(1) Factorial");
|
152
|
175
|
System.out.println("(2) Log");
|
153
|
176
|
System.out.println("(3) Inverse log (10^x)");
|
154
|
177
|
System.out.println("(4) Natural log (Ln x)");
|
155
|
178
|
System.out.println("(5) Inverse Natural log (e^x)");
|
156
|
|
- System.out.println("(6) custom 1"); //add custom 1
|
157
|
|
- System.out.println("(7) Exponentiation");//add custom 2
|
|
179
|
+ System.out.println("(6) Cubed root"); //add custom 1
|
|
180
|
+ System.out.println("(7) Absolute value");//add custom 2
|
|
181
|
+ System.out.println("-------------------------------------------------");
|
|
182
|
+ System.out.print("> ");
|
158
|
183
|
choice = stdin.nextInt();
|
159
|
184
|
|
160
|
185
|
switch(choice){
|
161
|
|
- case 1:
|
|
186
|
+ case 1: System.out.println("Calculating factorial of " + num);
|
|
187
|
+ int i;
|
|
188
|
+ double fct = 1;
|
|
189
|
+ for(i=2; i<num; i++){
|
|
190
|
+ fct *= i;
|
|
191
|
+ }
|
|
192
|
+ result = fct;
|
162
|
193
|
isValid = true;
|
163
|
194
|
break;
|
164
|
|
- case 2:
|
|
195
|
+ case 2: System.out.println("Calculating log of " + num);
|
|
196
|
+ result = Math.log10(num);
|
165
|
197
|
isValid = true;
|
166
|
198
|
break;
|
167
|
|
- case 3:
|
|
199
|
+ case 3: System.out.println("Calculating inverse log (10^x) of " + num);
|
|
200
|
+ result = Math.pow(10 , Math.log10(num));
|
168
|
201
|
isValid = true;
|
169
|
202
|
break;
|
170
|
|
- case 4:
|
|
203
|
+ case 4: System.out.println("Calculating natural log (Ln) of " + num);
|
|
204
|
+ result = Math.log(num);
|
171
|
205
|
isValid = true;
|
172
|
206
|
break;
|
173
|
|
- case 5:
|
|
207
|
+ case 5: System.out.println("Calculating inverese natural log (e^x) of " + num);
|
|
208
|
+ result = Math.exp(num);
|
174
|
209
|
isValid = true;
|
175
|
210
|
break;
|
176
|
|
- case 6:
|
|
211
|
+ case 6: System.out.println("Calculating cubed root of " + num);
|
|
212
|
+ result = Math.cbrt(num);
|
177
|
213
|
isValid = true;
|
178
|
214
|
break;
|
179
|
|
- case 7:
|
180
|
|
- isValid = true;
|
181
|
|
- break;
|
182
|
|
- case 8:
|
183
|
|
- isValid = true;
|
184
|
|
- break;
|
185
|
|
- case 9:
|
|
215
|
+ case 7: System.out.println("Calculating absolute value of " + num);
|
|
216
|
+ result = Math.abs(num);
|
186
|
217
|
isValid = true;
|
187
|
218
|
break;
|
188
|
219
|
default:
|
|
220
|
+ break;
|
189
|
221
|
|
190
|
222
|
}
|
191
|
223
|
}
|
192
|
|
- return 3;
|
|
224
|
+ return result;
|
193
|
225
|
}
|
194
|
226
|
|
195
|
227
|
}
|