Преглед на файлове

updating memory functions

Trinh Tong преди 6 години
родител
ревизия
aad32b341f
променени са 2 файла, в които са добавени 33 реда и са изтрити 48 реда
  1. 32
    25
      Console.java
  2. 1
    23
      SwitchDisplay.java

+ 32
- 25
Console.java Целия файл

@@ -16,17 +16,6 @@ public class Console {
16 16
         SwitchDisplay baseChange = new SwitchDisplay();
17 17
         Trig trigMenu = new Trig();
18 18
 
19
-        // Stored memory value should be able to be used throughout whole application
20
-        Double memoryValue = memory.memory;
21
-
22
-        // Ask if you want to use memory, KEEP TRACK OF MEMORY USE
23
-        // by boolean
24
-        Boolean memoryChanged = memory.memoryChanged;
25
-
26
-        // we use 1 input variable statement to call the user to input, then manipulate
27
-        // Can user input M if native type is double
28
-        // if any input = "m", that input now = memoryValue;
29
-
30 19
         // Menu Input
31 20
         String menuInput = " ";
32 21
         // Giant while loop that links back to main menu
@@ -38,35 +27,33 @@ public class Console {
38 27
                 // Basic Calculator
39 28
                 case "1":
40 29
                 basicCalc.Basic();
41
-                
30
+
42 31
                 double basicInput1 = 0,
43
-                       basicInput2 = 0;
44
-                       
32
+                basicInput2 = 0;
33
+
45 34
                 String basicMode = Console.getStringInput("Enter the mode: ");
46
-                
35
+
47 36
                 if (memory.memoryChanged != true) {
48 37
                     basicInput1 = Console.getDoubleInput("Enter the first input: ");
49 38
                     basicInput2 = Console.getDoubleInput("Enter the second input: ");
50
-                } else if (memoryChanged == true) {
39
+                } else if (memory.memoryChanged == true) {
51 40
                     String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
52 41
                     if (useMemory.equals("y")) {
53 42
                         String whichBasInput = Console.getStringInput("Which input? 1 or 2 or both").toLowerCase();
54 43
                         if (whichBasInput.equals("1")) {
55
-                            basicInput1 = memoryValue;
44
+                            basicInput1 = memory.memory;
56 45
                             basicInput2 = Console.getDoubleInput("Enter the second input: ");
57 46
                         } else if (whichBasInput.equals("2")) {
58
-                            basicInput2 = memoryValue;
47
+                            basicInput2 = memory.memory;
59 48
                             basicInput1 = Console.getDoubleInput("Enter the first input: ");
60 49
                         } else if (whichBasInput.equals("both")) {
61
-                            basicInput1 = memoryValue;
62
-                            basicInput2 = memoryValue;
50
+                            basicInput1 = memory.memory;
51
+                            basicInput2 = memory.memory;
63 52
                         }
64 53
                     }
65 54
                 }
66
-                
67 55
 
68 56
                 double basicAnswer = 0;
69
-
70 57
                 if (basicMode.equals("1")) {
71 58
                     basicAnswer = basicCalc.getSum(basicInput1, basicInput2);
72 59
 
@@ -142,12 +129,32 @@ public class Console {
142 129
                     String baseMode = "";
143 130
 
144 131
                     baseChange.switchDisplay(); 
132
+                    String baseAnswer = "";
145 133
                     baseMode = Console.getStringInput("Enter the desired display mode: ");
146
-
147 134
                     int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
148 135
 
149
-                    String baseOutput = baseChange.switchDisplayOutput(baseMode, userInput);
150
-                    Console.println(baseOutput);
136
+                    switch (baseMode) {
137
+                        case "1":
138
+                        baseAnswer = baseChange.toBinary(userInput);
139
+
140
+                        case "2":
141
+                        baseAnswer = baseChange.toOctal(userInput);
142
+
143
+                        case "3":
144
+                        baseAnswer = baseChange.toDecimal(userInput);
145
+
146
+                        case "4":
147
+                        baseAnswer = baseChange.toHexa(userInput);
148
+
149
+                        case "5":
150
+                        break;
151
+
152
+                        default:
153
+                        Console.println("Invalid Input");
154
+                        break;
155
+                    }
156
+                    
157
+                    Console.println(baseAnswer);
151 158
 
152 159
                     break;
153 160
                     // display mode

+ 1
- 23
SwitchDisplay.java Целия файл

@@ -40,29 +40,7 @@ public class SwitchDisplay
40 40
                              + "\n5: Cancel - returns to Main Menu");
41 41
                          
42 42
     }
43
-    
44
-    public String switchDisplayOutput(String mode, int baseInput) {
45
-        switch (mode) {
46
-            case "1":
47
-                return toBinary(baseInput);
48
-                
49
-            case "2":
50
-                return toOctal(baseInput);
51
-                
52
-            case "3":
53
-                return toDecimal(baseInput);
54
-                
55
-            case "4":
56
-                return toHexa(baseInput);
57
-                
58
-            case "5":
59
-                break;
60
-                
61
-            default:
62
-                return "Invalid Input";
63
-        }
64
-    }
65
-    
43
+
66 44
     /**
67 45
      * Converts the user input into corresponding base types
68 46
      */