MemoryFunc.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. */
  3. public class MemoryFunc {
  4. public Double memory;
  5. public Boolean memoryChanged;
  6. public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
  7. public MemoryFunc() {
  8. this.memory = DEFAULT_MEMORY_VALUE;
  9. this.memoryChanged = false;
  10. }
  11. /**
  12. * Menu
  13. * Clear
  14. * Print
  15. * Update
  16. */
  17. public void memoryMenu() {
  18. Console.println("Memory Menu"
  19. + "\n1: M+ - Update stored memory value"
  20. + "\n2: MC - Clear to default memory value"
  21. + "\n3: MCR - Display stored memory value"
  22. + "\n4: Cancel - Returns to Main Menu");
  23. String memoryOpt = "";
  24. while (!memoryOpt.equals("4")) {
  25. memoryOpt = Console.getStringInput("Select option by typing the key. (ie. 1 for M+)");
  26. if (memoryOpt.equals("1")) {
  27. Double newMemory = Console.getDoubleInput("Enter the value to store");
  28. this.memory = updateMemory(newMemory);
  29. this.memoryChanged = true;
  30. break;
  31. } else if (memoryOpt.equals("2")) {
  32. clearMemory();
  33. Console.println("Memory cleared.");
  34. break;
  35. } else if (memoryOpt.equals("3")) {
  36. Console.println("Stored Value: " + displayMemory());
  37. break;
  38. } else {
  39. Console.println("Invalid Option");
  40. }
  41. }
  42. }
  43. public Double updateMemory(Double memoryInput) {
  44. return this.memory = memoryInput;
  45. }
  46. public Double clearMemory() {
  47. return this.memory = DEFAULT_MEMORY_VALUE;
  48. }
  49. public Double displayMemory() {
  50. return this.memory;
  51. }
  52. }