|
@@ -0,0 +1,195 @@
|
|
1
|
+import java.util.Scanner;
|
|
2
|
+import java.lang.*;
|
|
3
|
+
|
|
4
|
+public class Operations{
|
|
5
|
+
|
|
6
|
+ Scanner stdin = new Scanner(System.in);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+public double chooseOp(double num){
|
|
10
|
+
|
|
11
|
+ boolean isValid = false;
|
|
12
|
+ int choice;
|
|
13
|
+ double result = -1;
|
|
14
|
+
|
|
15
|
+ while(!isValid){
|
|
16
|
+ System.out.println("Select type of operation to perform (enter # 1-3)");
|
|
17
|
+ System.out.println("(1) Core Functions");
|
|
18
|
+ System.out.println("(2) Trigonometry");
|
|
19
|
+ System.out.println("(3) Advanced Functions");
|
|
20
|
+ choice = stdin.nextInt();
|
|
21
|
+
|
|
22
|
+ switch(choice){
|
|
23
|
+ case 1: result = coreFunc(num);
|
|
24
|
+ isValid = true;
|
|
25
|
+ break;
|
|
26
|
+ case 2:trigFunc();
|
|
27
|
+ isValid = true;
|
|
28
|
+ break;
|
|
29
|
+ case 3:advFunc();
|
|
30
|
+ isValid = true;
|
|
31
|
+ break;
|
|
32
|
+ default:
|
|
33
|
+ break;
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+ return result;
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+public double coreFunc(double num){ //take displayNum as input parameter
|
|
40
|
+
|
|
41
|
+ boolean isValid = false;
|
|
42
|
+ int choice;
|
|
43
|
+ double entNum, result = -1;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+ while(!isValid){
|
|
47
|
+ System.out.println("Select core function to perform (enter # 1-3)");
|
|
48
|
+ System.out.println("(1) Add");
|
|
49
|
+ System.out.println("(2) Subtract");
|
|
50
|
+ System.out.println("(3) Multiply");
|
|
51
|
+ System.out.println("(4) Divide");
|
|
52
|
+ System.out.println("(5) Square");
|
|
53
|
+ System.out.println("(6) Square Root");
|
|
54
|
+ System.out.println("(7) Exponentiation");
|
|
55
|
+ System.out.println("(8) Inverse (1/x)");
|
|
56
|
+ System.out.println("(9) Change sign (+/-)");
|
|
57
|
+ choice = stdin.nextInt();
|
|
58
|
+
|
|
59
|
+ switch(choice){
|
|
60
|
+ case 1: System.out.println("Enter number to add to " + num + ": ");
|
|
61
|
+ entNum = stdin.nextDouble();
|
|
62
|
+ result = num + entNum;
|
|
63
|
+ isValid = true;
|
|
64
|
+ break;
|
|
65
|
+ case 2: System.out.println("Enter number to subtract from " + num + ": ");
|
|
66
|
+ entNum = stdin.nextDouble();
|
|
67
|
+ result = num - entNum;
|
|
68
|
+ isValid = true;
|
|
69
|
+ break;
|
|
70
|
+ case 3: System.out.println("Enter number to multiply to " + num + ": ");
|
|
71
|
+ entNum = stdin.nextDouble();
|
|
72
|
+ result = num * entNum;
|
|
73
|
+ isValid = true;
|
|
74
|
+ break;
|
|
75
|
+ case 4: System.out.println("Enter number to divide from " + num + ": ");
|
|
76
|
+ entNum = stdin.nextDouble();
|
|
77
|
+ result = num / entNum; //use Double.isNaN(x)
|
|
78
|
+ isValid = true;
|
|
79
|
+ break;
|
|
80
|
+ case 5:
|
|
81
|
+ isValid = true;
|
|
82
|
+ break;
|
|
83
|
+ case 6:
|
|
84
|
+ isValid = true;
|
|
85
|
+ break;
|
|
86
|
+ case 7:
|
|
87
|
+ isValid = true;
|
|
88
|
+ break;
|
|
89
|
+ case 8:
|
|
90
|
+ isValid = true;
|
|
91
|
+ break;
|
|
92
|
+ case 9:
|
|
93
|
+ isValid = true;
|
|
94
|
+ break;
|
|
95
|
+ default:
|
|
96
|
+ break;
|
|
97
|
+ }
|
|
98
|
+ }
|
|
99
|
+ return result;
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+public double trigFunc(){ //take displayNum as input parameter
|
|
104
|
+
|
|
105
|
+ boolean isValid = false;
|
|
106
|
+ int choice;
|
|
107
|
+ double result = -1;
|
|
108
|
+
|
|
109
|
+ while(!isValid){
|
|
110
|
+ System.out.println("Select trigonemtric function to perform (enter # 1-3)");
|
|
111
|
+ System.out.println("(1) Sin");
|
|
112
|
+ System.out.println("(2) Cos");
|
|
113
|
+ System.out.println("(3) Tangent");
|
|
114
|
+ System.out.println("(4) ArcSin");
|
|
115
|
+ System.out.println("(5) ArcCos");
|
|
116
|
+ System.out.println("(6) ArcTan");
|
|
117
|
+ choice = stdin.nextInt();
|
|
118
|
+
|
|
119
|
+ switch(choice){
|
|
120
|
+ case 1:
|
|
121
|
+ isValid = true;
|
|
122
|
+ break;
|
|
123
|
+ case 2:
|
|
124
|
+ isValid = true;
|
|
125
|
+ break;
|
|
126
|
+ case 3:
|
|
127
|
+ isValid = true;
|
|
128
|
+ break;
|
|
129
|
+ case 4:
|
|
130
|
+ isValid = true;
|
|
131
|
+ break;
|
|
132
|
+ case 5:
|
|
133
|
+ isValid = true;
|
|
134
|
+ break;
|
|
135
|
+ case 6:
|
|
136
|
+ isValid = true;
|
|
137
|
+ break;
|
|
138
|
+
|
|
139
|
+ }
|
|
140
|
+ }
|
|
141
|
+ return 2;
|
|
142
|
+}
|
|
143
|
+
|
|
144
|
+public double advFunc(){ //take displayNum as input parameter
|
|
145
|
+
|
|
146
|
+ boolean isValid = false;
|
|
147
|
+ int choice;
|
|
148
|
+
|
|
149
|
+ while(!isValid){
|
|
150
|
+ System.out.println("Select advanced function to perform (enter # 1-3)");
|
|
151
|
+ System.out.println("(1) Factorial");
|
|
152
|
+ System.out.println("(2) Log");
|
|
153
|
+ System.out.println("(3) Inverse log (10^x)");
|
|
154
|
+ System.out.println("(4) Natural log (Ln x)");
|
|
155
|
+ 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
|
|
158
|
+ choice = stdin.nextInt();
|
|
159
|
+
|
|
160
|
+ switch(choice){
|
|
161
|
+ case 1:
|
|
162
|
+ isValid = true;
|
|
163
|
+ break;
|
|
164
|
+ case 2:
|
|
165
|
+ isValid = true;
|
|
166
|
+ break;
|
|
167
|
+ case 3:
|
|
168
|
+ isValid = true;
|
|
169
|
+ break;
|
|
170
|
+ case 4:
|
|
171
|
+ isValid = true;
|
|
172
|
+ break;
|
|
173
|
+ case 5:
|
|
174
|
+ isValid = true;
|
|
175
|
+ break;
|
|
176
|
+ case 6:
|
|
177
|
+ isValid = true;
|
|
178
|
+ break;
|
|
179
|
+ case 7:
|
|
180
|
+ isValid = true;
|
|
181
|
+ break;
|
|
182
|
+ case 8:
|
|
183
|
+ isValid = true;
|
|
184
|
+ break;
|
|
185
|
+ case 9:
|
|
186
|
+ isValid = true;
|
|
187
|
+ break;
|
|
188
|
+ default:
|
|
189
|
+
|
|
190
|
+ }
|
|
191
|
+ }
|
|
192
|
+ return 3;
|
|
193
|
+}
|
|
194
|
+
|
|
195
|
+}
|