|
@@ -5,15 +5,16 @@ public class Operations{
|
5
|
5
|
|
6
|
6
|
Scanner stdin = new Scanner(System.in);
|
7
|
7
|
|
8
|
|
-
|
9
|
8
|
public double chooseOp(double num){
|
10
|
9
|
|
11
|
10
|
boolean isValid = false;
|
12
|
11
|
int choice;
|
13
|
|
- double result = -1;
|
|
12
|
+ double result = 0;
|
14
|
13
|
|
15
|
14
|
while(!isValid){
|
16
|
15
|
System.out.println("\n-------------------------------------------------");
|
|
16
|
+ System.out.println(num);
|
|
17
|
+ System.out.println("-------------------------------------------------");
|
17
|
18
|
System.out.println("Select type of operation to perform (enter # 1-3)");
|
18
|
19
|
System.out.println("(1) Core Functions");
|
19
|
20
|
System.out.println("(2) Trigonometry");
|
|
@@ -47,7 +48,9 @@ public double coreFunc(double num){ //take displayNum as input parameter
|
47
|
48
|
|
48
|
49
|
|
49
|
50
|
while(!isValid){
|
50
|
|
- System.out.println("\n---------------------------------------------");
|
|
51
|
+ System.out.println("\n-------------------------------------------------");
|
|
52
|
+ System.out.println(num);
|
|
53
|
+ System.out.println("-------------------------------------------------");
|
51
|
54
|
System.out.println("Select core function to perform (enter # 1-9)");
|
52
|
55
|
System.out.println("(1) Add");
|
53
|
56
|
System.out.println("(2) Subtract");
|
|
@@ -64,43 +67,52 @@ public double coreFunc(double num){ //take displayNum as input parameter
|
64
|
67
|
|
65
|
68
|
switch(choice){
|
66
|
69
|
case 1: System.out.println("Enter number to add to " + num + ": ");
|
|
70
|
+ System.out.print("> ");
|
67
|
71
|
entNum = stdin.nextDouble();
|
68
|
72
|
result = num + entNum;
|
69
|
73
|
isValid = true;
|
70
|
74
|
break;
|
71
|
75
|
case 2: System.out.println("Enter number to subtract from " + num + ": ");
|
|
76
|
+ System.out.print("> ");
|
72
|
77
|
entNum = stdin.nextDouble();
|
73
|
78
|
result = num - entNum;
|
74
|
79
|
isValid = true;
|
75
|
80
|
break;
|
76
|
81
|
case 3: System.out.println("Enter number to multiply to " + num + ": ");
|
|
82
|
+ System.out.print("> ");
|
77
|
83
|
entNum = stdin.nextDouble();
|
78
|
84
|
result = num * entNum;
|
79
|
85
|
isValid = true;
|
80
|
86
|
break;
|
81
|
87
|
case 4: System.out.println("Enter number to divide from " + num + ": ");
|
|
88
|
+ System.out.print("> ");
|
82
|
89
|
entNum = stdin.nextDouble();
|
83
|
90
|
result = num / entNum; //use Double.isNaN(x)
|
84
|
91
|
isValid = true;
|
85
|
92
|
break;
|
86
|
93
|
case 5: System.out.println("Squaring number on display (" + num + "^2) ");
|
|
94
|
+ System.out.print("> ");
|
87
|
95
|
result = num * num;
|
88
|
96
|
isValid = true;
|
89
|
97
|
break;
|
90
|
98
|
case 6: System.out.println("Taking square root of " + num);//cant take negative #
|
|
99
|
+ System.out.print("> ");
|
91
|
100
|
result = Math.sqrt(num);
|
92
|
101
|
isValid = true;
|
93
|
102
|
break;
|
94
|
103
|
case 7: System.out.println("Enter exponent to raise " + num + " to (" + num + "^n)");
|
|
104
|
+ System.out.print("> ");
|
95
|
105
|
entNum = stdin.nextDouble();
|
96
|
106
|
result = num * entNum;
|
97
|
107
|
isValid = true;
|
98
|
108
|
break;
|
99
|
109
|
case 8: System.out.println("Calculating inverse of " + num + " (1/" + num + ")");
|
|
110
|
+ System.out.print("> ");
|
100
|
111
|
result = 1/num;
|
101
|
112
|
isValid = true;
|
102
|
113
|
break;
|
103
|
114
|
case 9: System.out.println("Calculating negation of " + num + " (n -> -n , -n -> n)");
|
|
115
|
+ System.out.print("> ");
|
104
|
116
|
result = num * -1;
|
105
|
117
|
isValid = true;
|
106
|
118
|
break;
|
|
@@ -119,7 +131,9 @@ public double trigFunc(double num){ //take displayNum as input parameter
|
119
|
131
|
double result = -0;
|
120
|
132
|
|
121
|
133
|
while(!isValid){
|
122
|
|
- System.out.println("\n--------------------------------------------");
|
|
134
|
+ System.out.println("\n-------------------------------------------------");
|
|
135
|
+ System.out.println(num);
|
|
136
|
+ System.out.println("-------------------------------------------------");
|
123
|
137
|
System.out.println("Select trigonemtric function (enter # 1-6)");
|
124
|
138
|
System.out.println("(1) Sin");
|
125
|
139
|
System.out.println("(2) Cos");
|
|
@@ -170,6 +184,8 @@ public double advFunc(double num){ //take displayNum as input parameter
|
170
|
184
|
|
171
|
185
|
while(!isValid){
|
172
|
186
|
System.out.println("\n-------------------------------------------------");
|
|
187
|
+ System.out.println(num);
|
|
188
|
+ System.out.println("-------------------------------------------------");
|
173
|
189
|
System.out.println("Select advanced function to perform (enter # 1-7)");
|
174
|
190
|
System.out.println("(1) Factorial");
|
175
|
191
|
System.out.println("(2) Log");
|