|
@@ -10,7 +10,16 @@ public class Operations
|
10
|
10
|
{
|
11
|
11
|
/**
|
12
|
12
|
* prompting a user for a command solving for that command
|
|
13
|
+ *
|
13
|
14
|
*/
|
|
15
|
+ public static void printHelp(){
|
|
16
|
+ System.out.println("\n? | + | - | * | / |");
|
|
17
|
+ System.out.println("^ | sqrt | exp | inverse |");
|
|
18
|
+ System.out.println("cos | sine | tan | cos-1 | sin-1 | m+ | m- | MRC");
|
|
19
|
+ System.out.println("log | ln | ex |");
|
|
20
|
+ System.out.println("to clear display enter clrDisplay\n");
|
|
21
|
+ }
|
|
22
|
+
|
14
|
23
|
public static Double runCommand()
|
15
|
24
|
{
|
16
|
25
|
// put your code here
|
|
@@ -30,55 +39,98 @@ public class Operations
|
30
|
39
|
System.out.print("Thanks for calculating with us!");
|
31
|
40
|
break;
|
32
|
41
|
}
|
33
|
|
- if (command.equalsIgnoreCase("sine")) {
|
34
|
|
- result = ScientificFunctions.sine(Console.getDoubleInput("Enter number"));
|
|
42
|
+ else if (command.equalsIgnoreCase("sine")) {
|
|
43
|
+ if (result != 0){
|
|
44
|
+ result = ScientificFunctions.sine(result);
|
|
45
|
+ }
|
|
46
|
+ else{
|
|
47
|
+ result = ScientificFunctions.sine(Console.getDoubleInput("Enter number"));
|
|
48
|
+ }
|
35
|
49
|
Console.printResult(result);
|
36
|
50
|
}
|
37
|
|
- if (command.equalsIgnoreCase("cos")) {
|
38
|
|
- result = ScientificFunctions.cosine(Console.getDoubleInput("Enter number"));
|
|
51
|
+ else if (command.equalsIgnoreCase("cos")) {
|
|
52
|
+ if (result != 0){
|
|
53
|
+ result = ScientificFunctions.cosine(result);
|
|
54
|
+ }
|
|
55
|
+ else{
|
|
56
|
+ result = ScientificFunctions.cosine(Console.getDoubleInput("Enter number"));
|
|
57
|
+ }
|
39
|
58
|
Console.printResult(result);
|
40
|
59
|
}
|
41
|
|
- if (command.equalsIgnoreCase("tan")) {
|
42
|
|
- result = ScientificFunctions.tangent(Console.getDoubleInput("Enter number"));
|
|
60
|
+ else if (command.equalsIgnoreCase("tan")) {
|
|
61
|
+ if (result != 0){
|
|
62
|
+ result = ScientificFunctions.tangent(result);
|
|
63
|
+ }
|
|
64
|
+ else{
|
|
65
|
+ result = ScientificFunctions.tangent(Console.getDoubleInput("Enter number"));
|
|
66
|
+ }
|
43
|
67
|
Console.printResult(result);
|
44
|
68
|
}
|
45
|
|
- if (command.equalsIgnoreCase("cos-1")) {
|
46
|
|
- result = ScientificFunctions.inverseCosine(Console.getDoubleInput("Enter number"));
|
|
69
|
+ else if (command.equalsIgnoreCase("cos-1")) {
|
|
70
|
+ if (result != 0){
|
|
71
|
+ result = ScientificFunctions.inverseCosine(result);
|
|
72
|
+ }
|
|
73
|
+ else{
|
|
74
|
+ result = ScientificFunctions.inverseCosine(Console.getDoubleInput("Enter number"));
|
|
75
|
+ }
|
47
|
76
|
Console.printResult(result);
|
48
|
77
|
}
|
49
|
|
- if (command.equalsIgnoreCase("sin-1")) {
|
50
|
|
- result = ScientificFunctions.inverseSine(Console.getDoubleInput("Enter number"));
|
|
78
|
+ else if (command.equalsIgnoreCase("sin-1")) {
|
|
79
|
+ if (result != 0){
|
|
80
|
+ result = ScientificFunctions.inverseSine(result);
|
|
81
|
+ }
|
|
82
|
+ else{
|
|
83
|
+ result = ScientificFunctions.inverseSine(Console.getDoubleInput("Enter number"));
|
|
84
|
+ }
|
51
|
85
|
Console.printResult(result);
|
52
|
86
|
}
|
53
|
|
- if (command.equalsIgnoreCase("tan-1")) {
|
54
|
|
- result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number"));
|
|
87
|
+ else if (command.equalsIgnoreCase("tan-1")) {
|
|
88
|
+ if (result != 0){
|
|
89
|
+ result = ScientificFunctions.inverseTangent(result);
|
|
90
|
+ }
|
|
91
|
+ else{
|
|
92
|
+ result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number"));
|
|
93
|
+ }
|
55
|
94
|
Console.printResult(result);
|
56
|
95
|
}
|
57
|
|
- if(command.equalsIgnoreCase("m+")){
|
|
96
|
+ else if(command.equalsIgnoreCase("M+")){
|
58
|
97
|
memory.storeInMemory(result);
|
59
|
98
|
Console.printResult(result);
|
60
|
99
|
}
|
61
|
|
-
|
62
|
|
- if (command.equalsIgnoreCase("m-")){
|
|
100
|
+
|
|
101
|
+ else if (command.equalsIgnoreCase("M-")){
|
|
102
|
+ Console.printResult(memory.clearMemory());
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ else if (command.equalsIgnoreCase("MRC")){
|
63
|
106
|
Console.printResult(memory.retrieveFromMemory());
|
64
|
107
|
}
|
65
|
|
-
|
66
|
|
- if (command.equalsIgnoreCase("switchmode")){
|
|
108
|
+
|
|
109
|
+ else if (command.equalsIgnoreCase("switchmode")){
|
67
|
110
|
displayMode.setResult(result);
|
68
|
111
|
String mode = displayMode.enterMode();
|
69
|
112
|
//System.out.println(mode);
|
70
|
113
|
displayMode.switchDisplayMode(mode);
|
71
|
|
-
|
|
114
|
+
|
72
|
115
|
}
|
73
|
|
- if (command.equalsIgnoreCase("log")){
|
|
116
|
+ else if (command.equalsIgnoreCase("log")){
|
74
|
117
|
Console.printResult(bonusFunctions.LogBaseTenOfAnumber(result));
|
75
|
118
|
}
|
76
|
|
- if (command.equalsIgnoreCase("ln")){
|
|
119
|
+ else if (command.equalsIgnoreCase("ln")){
|
77
|
120
|
Console.printResult(bonusFunctions.naturalLogLn(result));
|
78
|
121
|
}
|
79
|
|
- if (command.equalsIgnoreCase("ex")){
|
|
122
|
+ else if (command.equalsIgnoreCase("ex")){
|
80
|
123
|
Console.printResult(bonusFunctions.exponential(result));
|
81
|
124
|
}
|
|
125
|
+ else if(command.equalsIgnoreCase("?")){
|
|
126
|
+ printHelp();
|
|
127
|
+ }
|
|
128
|
+ else if(command.equalsIgnoreCase("clrDisplay")){
|
|
129
|
+ result = 0.0;
|
|
130
|
+ }
|
|
131
|
+ else{
|
|
132
|
+ Console.println("Invalid command please press ? for help");
|
|
133
|
+ }
|
82
|
134
|
//firstNumber = result;
|
83
|
135
|
// and on and on
|
84
|
136
|
}
|