浏览代码

Added memory statements to console

Trinh Tong 6 年前
父节点
当前提交
8004e80829
共有 2 个文件被更改,包括 68 次插入22 次删除
  1. 62
    16
      Console.java
  2. 6
    6
      SwitchDisplay.java

+ 62
- 16
Console.java 查看文件

@@ -1,5 +1,6 @@
1 1
 
2 2
 import java.util.Scanner;
3
+import java.util.*;
3 4
 /**
4 5
  * Created by leon on 2/9/18.
5 6
  */
@@ -50,6 +51,9 @@ public class Console {
50 51
                             basicInput1 = memory.memory;
51 52
                             basicInput2 = memory.memory;
52 53
                         }
54
+                    } else {
55
+                        basicInput1 = Console.getDoubleInput("Enter the first input: ");
56
+                        basicInput2 = Console.getDoubleInput("Enter the second input: ");
53 57
                     }
54 58
                 }
55 59
 
@@ -90,19 +94,40 @@ public class Console {
90 94
                 break;
91 95
 
92 96
                 case "2":
97
+
93 98
                 advCalc.realAdvanced();
94 99
                 String mode = Console.getStringInput("Enter the mode: ");
95
-
96
-                double advInput1 = Console.getDoubleInput("Enter the first input: ");
100
+                double advInput1 = 0,
101
+                advInput2 = 0;
102
+                // checking if user wants to use memory
103
+                if (memory.memoryChanged != true) {
104
+                    advInput1 = Console.getDoubleInput("Enter the first input: ");
105
+                } else if (memory.memoryChanged == true) {
106
+                    String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
107
+                    if (useMemory.equals("y")) {
108
+                        advInput1 = memory.memory;
109
+                    } else if (useMemory.equals("n")) {
110
+                        advInput1 = Console.getDoubleInput("Enter the first input: ");
111
+                    }
112
+                }
97 113
 
98 114
                 double advAnswer = 0;
99
-
100 115
                 if (mode.equals("1")){
101 116
                     advAnswer = advCalc.squared(advInput1);
102 117
 
103 118
                 }else if (mode.equals("2")){
104 119
 
105
-                    double advInput2 = Console.getDoubleInput("Enter the exponent value: ");
120
+                    // checking if user wants to use memory
121
+                    if (memory.memoryChanged != true) {
122
+                        advInput2 = Console.getDoubleInput("Enter the exponent value: ");
123
+                    } else if (memory.memoryChanged == true) {
124
+                        String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
125
+                        if (useMemory.equals("y")) {
126
+                            advInput2 = memory.memory;
127
+                        } else if (useMemory.equals("n")) {
128
+                            advInput2 = Console.getDoubleInput("Enter the first input: ");
129
+                        }
130
+                    }
106 131
                     advAnswer = advCalc.exponent(advInput1,advInput2);
107 132
 
108 133
                 }else if (mode.equals("3")){
@@ -110,8 +135,8 @@ public class Console {
110 135
                         Console.println("undefined");
111 136
                         advAnswer = Double.NaN;
112 137
                     } else {
113
-                    advAnswer = advCalc.inverse(advInput1);
114
-                }
138
+                        advAnswer = advCalc.inverse(advInput1);
139
+                    }
115 140
                 }else if (mode.equals("4")){
116 141
                     advAnswer = advCalc.opposite(advInput1);
117 142
                 }else if (mode.equals("5")){
@@ -143,20 +168,31 @@ public class Console {
143 168
                     baseChange.switchDisplay();
144 169
                     String baseAnswer = "";
145 170
                     baseMode = Console.getStringInput("Enter the desired display mode: ");
146
-                    int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
171
+                    double userInput = 0;
172
+
173
+                    if (memory.memoryChanged != true) {
174
+                        userInput = (Console.getDoubleInput("Enter the exponent value: "));
175
+                    } else if (memory.memoryChanged == true) {
176
+                        String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
177
+                        if (useMemory.equals("y")) {
178
+                            userInput = memory.memory;
179
+                        } else if (useMemory.equals("n")) {
180
+                            userInput = Console.getDoubleInput("Enter the number you want to convert to selected base: ");
181
+                        }
182
+                    }
147 183
 
148 184
                     switch (baseMode) {
149 185
                         case "1":
150
-                        baseAnswer = baseChange.toBinary(userInput);
186
+                        baseAnswer = baseChange.toBinary((int)userInput);
151 187
 
152 188
                         case "2":
153
-                        baseAnswer = baseChange.toOctal(userInput);
189
+                        baseAnswer = baseChange.toOctal((int)userInput);
154 190
 
155 191
                         case "3":
156
-                        baseAnswer = baseChange.toDecimal(userInput);
192
+                        baseAnswer = baseChange.toDecimal((int)userInput);
157 193
 
158 194
                         case "4":
159
-                        baseAnswer = baseChange.toHexa(userInput);
195
+                        baseAnswer = baseChange.toHexa((int)userInput);
160 196
 
161 197
                         case "5":
162 198
                         break;
@@ -169,9 +205,7 @@ public class Console {
169 205
                     Console.println(baseAnswer);
170 206
 
171 207
                     break;
172
-                    // display mode
173
-                    // gets mode
174
-                    // asks for input
208
+
175 209
                 } else if (sciMenuInput.equals("2")) {
176 210
                     // Memory
177 211
                     // access memory menu
@@ -182,8 +216,20 @@ public class Console {
182 216
                     trigMenu.trigFunctions();
183 217
                     String trigMode = Console.getStringInput("Enter trignometric function by key: (ie. 1 for sin)");
184 218
 
185
-                    double trigInput = Console.getDoubleInput("Enter the input for the trignometric function: ");
186
-                    double trigAnswer = 0;
219
+                    double trigInput = 0;
220
+
221
+                    if (memory.memoryChanged != true) {
222
+                        trigInput = Console.getDoubleInput("Enter the input for the trignometric function: ");
223
+                    } else if (memory.memoryChanged == true) {
224
+                        String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
225
+                        if (useMemory.equals("y")) {
226
+                            trigInput = memory.memory;
227
+                        } else if (useMemory.equals("n")) {
228
+                            trigInput = Console.getDoubleInput("Enter the input for the trignometric function: ");
229
+                        }
230
+                    }
231
+
232
+                    double trigAnswer;
187 233
                     if (trigMode.equals("1")) {
188 234
                         trigAnswer = trigMenu.calcSin(trigInput);
189 235
 

+ 6
- 6
SwitchDisplay.java 查看文件

@@ -45,27 +45,27 @@ public class SwitchDisplay
45 45
      * Converts the user input into corresponding base types
46 46
      */
47 47
     
48
-    public String toBinary(int userInput) {
48
+    public String toBinary(double userInput) {
49 49
         
50
-        return Integer.toBinaryString(userInput);
50
+        return Integer.toBinaryString((int)userInput);
51 51
         
52 52
     }
53 53
     
54
-    public String toOctal(int userInput) {
54
+    public String toOctal(double userInput) {
55 55
         
56
-        return Integer.toOctalString(userInput);
56
+        return Integer.toOctalString((int)userInput);
57 57
         
58 58
     }
59 59
     
60 60
     public String toDecimal(int userInput) {
61 61
         
62
-        return Integer.toBinaryString(userInput);
62
+        return Integer.toBinaryString((int)userInput);
63 63
         
64 64
     }
65 65
     
66 66
     public String toHexa(int userInput) {
67 67
     
68
-        return Integer.toHexString(userInput);
68
+        return Integer.toHexString((int)userInput);
69 69
     
70 70
     }
71 71
 }