|
@@ -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
|
}
|