瀏覽代碼

Separated memory methods

Trinh Tong 6 年之前
父節點
當前提交
90f6a2442a
共有 2 個文件被更改,包括 51 次插入36 次删除
  1. 48
    0
      MemoryFunc.java
  2. 3
    36
      SciCalc.java

+ 48
- 0
MemoryFunc.java 查看文件

@@ -0,0 +1,48 @@
1
+
2
+/**
3
+ * Scientific Calculator Lab
4
+ * Trinh Tong
5
+ * Memory Class
6
+ */
7
+public class MemoryFunc
8
+{
9
+    // instance variables - replace the example below with your own
10
+    private double memory = 0;
11
+
12
+    /**
13
+     * Store 1 numeric value in memory for recall later
14
+     * M+ = add currently displayed value to the value in memorie (default = 0)
15
+     * MC = reset memory
16
+     * MRC = recall current valie from memory to display
17
+     */
18
+    public void memory()
19
+    {
20
+        // Memory menu
21
+        Console.println("Memory Mode");
22
+        // Ask for input of a number
23
+        double memoryInput = Console.getDoubleInput("Enter a number to store. ");
24
+        // Display memory keys
25
+        Console.println("Memory Options: " 
26
+                         + "\nM+ : adds input to memory"
27
+                         + "\nMC : clears current memory"
28
+                         + "\nMRC : displays current memory input");
29
+                         
30
+        String memorySelect = Console.getStringInput("What would you like to do? (Enter the key)");
31
+
32
+        
33
+        if (memorySelect.equals("M+") == true) {
34
+            // M+
35
+            memory = memoryInput;
36
+            
37
+        } else if (memorySelect.equals("MC") == true) {
38
+            // MC
39
+            memory = 0;
40
+            
41
+        } else if (memorySelect.equals("MCR") == true) {
42
+            // MCR
43
+            Console.println(Double.toString(memory));
44
+        
45
+        }
46
+        
47
+    }  
48
+}

+ 3
- 36
SciCalc.java 查看文件

@@ -49,42 +49,9 @@ public class SciCalc
49 49
         
50 50
     }
51 51
     
52
-    /**
53
-     * Store 1 numeric value in memory for recall later
54
-     * M+ = add currently displayed value to the value in memorie (default = 0)
55
-     * MC = reset memory
56
-     * MRC = recall current valie from memory to display
57
-     */
58
-    public void memory()
59
-    {
60
-        // Memory menu
61
-        Console.println("Memory Mode");
62
-        // Ask for input of a number
63
-        double memoryInput = Console.getDoubleInput("Enter a number to store. ");
64
-        // Display memory keys
65
-        Console.println("Memory Options: " 
66
-                         + "\nM+ : adds input to memory"
67
-                         + "\nMC : clears current memory"
68
-                         + "\nMRC : displays current memory input");
69
-                         
70
-        String memorySelect = Console.getStringInput("What would you like to do? (Enter the key)");
71
-
72
-        
73
-        if (memorySelect.equals("M+") == true) {
74
-            // M+
75
-            memory = memoryInput;
76
-            
77
-        } else if (memorySelect.equals("MC") == true) {
78
-            // MC
79
-            memory = 0;
80
-            
81
-        } else if (memorySelect.equals("MCR") == true) {
82
-            // MCR
83
-            Console.println(Double.toString(memory));
84
-        
85
-        }
86
-        
87
-    }  
52
+    public void toMemory() {
53
+        MemoryFunc memoryMenu = new MemoryFunc();
54
+    }
88 55
     
89 56
     
90 57
     /**