MemoryFunc.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. this.memoryChanged = false;
  35. break;
  36. } else if (memoryOpt.equals("3")) {
  37. Console.println("Stored Value: " + displayMemory());
  38. break;
  39. } else {
  40. Console.println("Invalid Option");
  41. }
  42. }
  43. }
  44. public Double updateMemory(Double memoryInput) {
  45. return this.memory = memoryInput;
  46. }
  47. public Double clearMemory() {
  48. return this.memory = DEFAULT_MEMORY_VALUE;
  49. }
  50. public Double displayMemory() {
  51. return this.memory;
  52. }
  53. }