MemoryFunc.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. */
  3. public class MemoryFunc {
  4. private Double memory;
  5. public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
  6. public MemoryFunc() {
  7. this.memory = DEFAULT_MEMORY_VALUE;
  8. }
  9. /**
  10. * Menu
  11. * Clear
  12. * Print
  13. * Update
  14. */
  15. public void memoryMenu() {
  16. Console.println("Memory Menu"
  17. + "\nM+: Update stored memory value"
  18. + "\nMC: Clear to default memory value"
  19. + "\nMCR: Display stored memory value"
  20. + "\nCancel: Returns to Main Menu");
  21. String memoryOpt = "";
  22. while (!memoryOpt.equals("cancel")) {
  23. memoryOpt = Console.getStringInput("Select option by typing the key").toLowerCase();
  24. if (memoryOpt.equals("m+")) {
  25. Double newMemory = Console.getDoubleInput("Enter the value to store");
  26. updateMemory(newMemory);
  27. break;
  28. } else if (memoryOpt.equals("mc")) {
  29. clearMemory();
  30. break;
  31. } else if (memoryOpt.equals("mcr")) {
  32. displayMemory();
  33. break;
  34. } else {
  35. Console.println("Invalid Option");
  36. }
  37. }
  38. }
  39. public void updateMemory(Double memoryInput) {
  40. this.memory = memoryInput;
  41. }
  42. public void clearMemory() {
  43. this.memory = DEFAULT_MEMORY_VALUE;
  44. }
  45. public void displayMemory() {
  46. Console.println(memory.toString());
  47. }
  48. }