Ver código fonte

Tested and updated methods

Trinh Tong 6 anos atrás
pai
commit
0ac93ed99e
2 arquivos alterados com 41 adições e 2 exclusões
  1. 9
    1
      MainApplication.java
  2. 32
    1
      MemoryFunc.java

+ 9
- 1
MainApplication.java Ver arquivo

@@ -8,6 +8,13 @@ import java.util.*;
8 8
 public class MainApplication {
9 9
     
10 10
     public static void main(String[] args) {
11
+        // Create all instances of classes to be used for this program
12
+        
13
+        MemoryFunc memory = new MemoryFunc();
14
+        
15
+        // Giant while loop that links back to main menu
16
+        memory.memoryMenu();
17
+        
11 18
         Console.println("Welcome to my calculator!");
12 19
         /** String s = Console.getStringInput("Enter a string");
13 20
         Integer i = Console.getIntegerInput("Enter an integer");
@@ -18,7 +25,8 @@ public class MainApplication {
18 25
         Console.println("The user input %s as a d", d);
19 26
         */
20 27
         
21
-        MemoryFunc memory = new MemoryFunc();
28
+        
29
+        
22 30
 
23 31
     }
24 32
 }

+ 32
- 1
MemoryFunc.java Ver arquivo

@@ -15,12 +15,43 @@ public class MemoryFunc {
15 15
      * Print
16 16
      * Update
17 17
      */
18
+    
18 19
     public void memoryMenu() {
20
+        
19 21
         Console.println("Memory Menu"
20 22
                          + "\nM+: Update stored memory value"
21 23
                          + "\nMC: Clear to default memory value"
22
-                         + "\nMCR: Display stored memory value" );
24
+                         + "\nMCR: Display stored memory value"
25
+                         + "\nCancel: Returns to Main Menu");
23 26
                          
27
+        String memoryOpt = "";
28
+        
29
+        while (!memoryOpt.equals("cancel")) {
30
+            
31
+            memoryOpt = Console.getStringInput("Select option by typing the key").toLowerCase();
32
+            
33
+            if (memoryOpt.equals("m+")) {
34
+                
35
+                Double newMemory = Console.getDoubleInput("Enter the value to store");
36
+                updateMemory(newMemory);
37
+                break;
38
+                
39
+            } else if (memoryOpt.equals("mc")) {
40
+                
41
+                clearMemory();
42
+                break;
43
+                
44
+            } else if (memoryOpt.equals("mcr")) {
45
+                
46
+                displayMemory();
47
+                break;
48
+                
49
+            } else {
50
+                
51
+                Console.println("Invalid Option");
52
+                
53
+            }
54
+        }
24 55
     }
25 56
     
26 57
     public void updateMemory(Double memoryInput) {