Browse Source

Tested and updated methods

Trinh Tong 6 years ago
parent
commit
f27a521cae
4 changed files with 53 additions and 55 deletions
  1. 8
    1
      MainApplication.java
  2. 30
    40
      MemoryFunc.java
  3. 3
    2
      SwitchDisplay.java
  4. 12
    12
      package.bluej

+ 8
- 1
MainApplication.java View File

3
 /**
3
 /**
4
  * Created by leon on 2/9/18.
4
  * Created by leon on 2/9/18.
5
  */
5
  */
6
+import java.util.*;
7
+
6
 public class MainApplication {
8
 public class MainApplication {
9
+    
7
     public static void main(String[] args) {
10
     public static void main(String[] args) {
8
         Console.println("Welcome to my calculator!");
11
         Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
12
+        /** String s = Console.getStringInput("Enter a string");
10
         Integer i = Console.getIntegerInput("Enter an integer");
13
         Integer i = Console.getIntegerInput("Enter an integer");
11
         Double d = Console.getDoubleInput("Enter a double.");
14
         Double d = Console.getDoubleInput("Enter a double.");
12
 
15
 
13
         Console.println("The user input %s as a string", s);
16
         Console.println("The user input %s as a string", s);
14
         Console.println("The user input %s as a integer", i);
17
         Console.println("The user input %s as a integer", i);
15
         Console.println("The user input %s as a d", d);
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 View File

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 View File

29
      * switchDisplayMode() rotates through the options
29
      * switchDisplayMode() rotates through the options
30
      * switchDisplayMode(String mode) sets the display to the mode given
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
         int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
35
         int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
35
         // try catch for int vs double or other input
36
         // try catch for int vs double or other input
40
                          + "\nHexadecimal"
41
                          + "\nHexadecimal"
41
                          + "\nCancel: returns to Main Menu");
42
                          + "\nCancel: returns to Main Menu");
42
         // Accepts next input to display mode.
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
         if (mode.equals("binary") == true) {
46
         if (mode.equals("binary") == true) {
46
             Console.println(baseInput + "in binary: " + toBinary(baseInput));
47
             Console.println(baseInput + "in binary: " + toBinary(baseInput));

+ 12
- 12
package.bluej View File

11
 dependency4.from=SciCalc
11
 dependency4.from=SciCalc
12
 dependency4.to=Trig
12
 dependency4.to=Trig
13
 dependency4.type=UsesDependency
13
 dependency4.type=UsesDependency
14
-dependency5.from=SwitchDisplay
14
+dependency5.from=MemoryFunc
15
 dependency5.to=Console
15
 dependency5.to=Console
16
 dependency5.type=UsesDependency
16
 dependency5.type=UsesDependency
17
-dependency6.from=MemoryFunc
17
+dependency6.from=SwitchDisplay
18
 dependency6.to=Console
18
 dependency6.to=Console
19
 dependency6.type=UsesDependency
19
 dependency6.type=UsesDependency
20
 editor.fx.0.height=722
20
 editor.fx.0.height=722
21
-editor.fx.0.width=980
21
+editor.fx.0.width=1120
22
 editor.fx.0.x=320
22
 editor.fx.0.x=320
23
-editor.fx.0.y=75
23
+editor.fx.0.y=140
24
 objectbench.height=214
24
 objectbench.height=214
25
 objectbench.width=595
25
 objectbench.width=595
26
 package.divider.horizontal=0.6
26
 package.divider.horizontal=0.6
56
 target2.x=10
56
 target2.x=10
57
 target2.y=280
57
 target2.y=280
58
 target3.height=50
58
 target3.height=50
59
-target3.name=Console
59
+target3.name=MemoryFunc
60
 target3.showInterface=false
60
 target3.showInterface=false
61
 target3.type=ClassTarget
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
 target4.height=50
65
 target4.height=50
66
-target4.name=MemoryFunc
66
+target4.name=Console
67
 target4.showInterface=false
67
 target4.showInterface=false
68
 target4.type=ClassTarget
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
 target5.height=50
72
 target5.height=50
73
 target5.name=Trig
73
 target5.name=Trig
74
 target5.showInterface=false
74
 target5.showInterface=false