Pārlūkot izejas kodu

Tested and updated methods

Trinh Tong 6 gadus atpakaļ
vecāks
revīzija
f27a521cae
4 mainītis faili ar 53 papildinājumiem un 55 dzēšanām
  1. 8
    1
      MainApplication.java
  2. 30
    40
      MemoryFunc.java
  3. 3
    2
      SwitchDisplay.java
  4. 12
    12
      package.bluej

+ 8
- 1
MainApplication.java Parādīt failu

@@ -3,15 +3,22 @@
3 3
 /**
4 4
  * Created by leon on 2/9/18.
5 5
  */
6
+import java.util.*;
7
+
6 8
 public class MainApplication {
9
+    
7 10
     public static void main(String[] args) {
8 11
         Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
12
+        /** String s = Console.getStringInput("Enter a string");
10 13
         Integer i = Console.getIntegerInput("Enter an integer");
11 14
         Double d = Console.getDoubleInput("Enter a double.");
12 15
 
13 16
         Console.println("The user input %s as a string", s);
14 17
         Console.println("The user input %s as a integer", i);
15 18
         Console.println("The user input %s as a d", d);
19
+        */
20
+        
21
+        MemoryFunc memory = new MemoryFunc();
22
+
16 23
     }
17 24
 }

+ 30
- 40
MemoryFunc.java Parādīt failu

@@ -1,48 +1,38 @@
1 1
 
2 2
 /**
3
- * Scientific Calculator Lab
4
- * Trinh Tong
5
- * Memory Class
3
+
6 4
  */
7
-public class MemoryFunc
8
-{
9
-    // instance variables - replace the example below with your own
10
-    private double memory = 0;
5
+public class MemoryFunc {
6
+    private Double memory;
7
+    public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
11 8
 
9
+    public MemoryFunc() {
10
+        this.memory = DEFAULT_MEMORY_VALUE;
11
+    }
12 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
13
+     * Menu
14
+     * Clear
15
+     * Print
16
+     * Update
17 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");
18
+    public void memoryMenu() {
19
+        Console.println("Memory Menu"
20
+                         + "\nM+: Update stored memory value"
21
+                         + "\nMC: Clear to default memory value"
22
+                         + "\nMCR: Display stored memory value" );
29 23
                          
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
-    }  
24
+    }
25
+    
26
+    public void updateMemory(Double memoryInput) {
27
+        this.memory = memoryInput;
28
+    }
29
+    
30
+    public void clearMemory() {
31
+        this.memory = DEFAULT_MEMORY_VALUE;
32
+    }
33
+    
34
+    public void displayMemory() {
35
+        Console.println(memory.toString());
36
+    }
37
+    
48 38
 }

+ 3
- 2
SwitchDisplay.java Parādīt failu

@@ -29,7 +29,8 @@ public class SwitchDisplay
29 29
      * switchDisplayMode() rotates through the options
30 30
      * switchDisplayMode(String mode) sets the display to the mode given
31 31
      */
32
-    public void switchDisplay(String mode)
32
+    
33
+    public void switchDisplay()
33 34
     {
34 35
         int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
35 36
         // try catch for int vs double or other input
@@ -40,7 +41,7 @@ public class SwitchDisplay
40 41
                          + "\nHexadecimal"
41 42
                          + "\nCancel: returns to Main Menu");
42 43
         // Accepts next input to display mode.
43
-        mode = Console.getStringInput("Enter the base option to display.").toLowerCase();
44
+        String mode = Console.getStringInput("Enter the base option to display.").toLowerCase();
44 45
         
45 46
         if (mode.equals("binary") == true) {
46 47
             Console.println(baseInput + "in binary: " + toBinary(baseInput));

+ 12
- 12
package.bluej Parādīt failu

@@ -11,16 +11,16 @@ dependency3.type=UsesDependency
11 11
 dependency4.from=SciCalc
12 12
 dependency4.to=Trig
13 13
 dependency4.type=UsesDependency
14
-dependency5.from=SwitchDisplay
14
+dependency5.from=MemoryFunc
15 15
 dependency5.to=Console
16 16
 dependency5.type=UsesDependency
17
-dependency6.from=MemoryFunc
17
+dependency6.from=SwitchDisplay
18 18
 dependency6.to=Console
19 19
 dependency6.type=UsesDependency
20 20
 editor.fx.0.height=722
21
-editor.fx.0.width=980
21
+editor.fx.0.width=1120
22 22
 editor.fx.0.x=320
23
-editor.fx.0.y=75
23
+editor.fx.0.y=140
24 24
 objectbench.height=214
25 25
 objectbench.width=595
26 26
 package.divider.horizontal=0.6
@@ -56,19 +56,19 @@ target2.width=80
56 56
 target2.x=10
57 57
 target2.y=280
58 58
 target3.height=50
59
-target3.name=Console
59
+target3.name=MemoryFunc
60 60
 target3.showInterface=false
61 61
 target3.type=ClassTarget
62
-target3.width=80
63
-target3.x=70
64
-target3.y=170
62
+target3.width=110
63
+target3.x=150
64
+target3.y=410
65 65
 target4.height=50
66
-target4.name=MemoryFunc
66
+target4.name=Console
67 67
 target4.showInterface=false
68 68
 target4.type=ClassTarget
69
-target4.width=110
70
-target4.x=150
71
-target4.y=410
69
+target4.width=80
70
+target4.x=70
71
+target4.y=170
72 72
 target5.height=50
73 73
 target5.name=Trig
74 74
 target5.showInterface=false