petervanhoef / Calculator-Brain

My solutions for CS193P Winter 2017 Assignment II: Calculator Brain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Task 7: Add buttons →M and M to Calculator’s UI

petervanhoef opened this issue · comments

Add two new buttons to your Calculator’s UI: →M and M. Don’t sacrifice any of the required operation buttons from Assignment 1 to add these (though you may add yet more operations buttons if you want). These two buttons will set and get (respectively) a variable in the CalculatorBrain called M.

  1. →M calls evaluate in your Model with a Dictionary which has a single entry whose key is M and whose value is the current value of the display, and then updates the display to show the result that comes back from evaluate. Until this button (or the clear button) is pressed again, this same Dictionary should be used every time evaluate is called.
  2. →M does not perform setOperand.
  3. Touching M should setOperand(variable: “M”) in the brain and then show the result of calling evaluate in the display.
  4. →M and M are Controller mechanics, not Model mechanics (though they both use the Model mechanic of variables).
  5. This is not a very great “memory” button on our Calculator, but it can be used for testing whether our variable function implemented in our Model is working properly. Examples ...
    9 + M = √ ⇒ description is √(9+M), display is 3 because M is not set (thus 0.0).
    7 →M ⇒ display now shows 4 (the square root of 16), description is still √(9+M) + 14 = ⇒ display now shows 18, description is now √(9+M)+14

Hint 8: Required Tasks 7 and 8 are Controller/View tasks ONLY. No additional changes in CalculatorBrain are required for these. For example, if M appears anywhere in your CalculatorBrain code, you’ve violated MVC. The M functionality is purely a UI feature that just happens to use the CalculatorBrain Model’s generic variable-processing functionality.