12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
-
- /**
-
- */
- public class MemoryFunc {
- private Double memory;
- public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
-
- public MemoryFunc() {
- this.memory = DEFAULT_MEMORY_VALUE;
- }
- /**
- * Menu
- * Clear
- * Print
- * Update
- */
-
- public void memoryMenu() {
-
- Console.println("Memory Menu"
- + "\nM+: Update stored memory value"
- + "\nMC: Clear to default memory value"
- + "\nMCR: Display stored memory value"
- + "\nCancel: Returns to Main Menu");
-
- String memoryOpt = "";
-
- while (!memoryOpt.equals("cancel")) {
-
- memoryOpt = Console.getStringInput("Select option by typing the key").toLowerCase();
-
- if (memoryOpt.equals("m+")) {
-
- Double newMemory = Console.getDoubleInput("Enter the value to store");
- updateMemory(newMemory);
- break;
-
- } else if (memoryOpt.equals("mc")) {
-
- clearMemory();
- break;
-
- } else if (memoryOpt.equals("mcr")) {
-
- displayMemory();
- break;
-
- } else {
-
- Console.println("Invalid Option");
-
- }
- }
- }
-
- public void updateMemory(Double memoryInput) {
- this.memory = memoryInput;
- }
-
- public void clearMemory() {
- this.memory = DEFAULT_MEMORY_VALUE;
- }
-
- public void displayMemory() {
- Console.println(memory.toString());
- }
-
- }
|