Skip to content
Choose a tag to compare

assignment #2 task #7

@m2mtech m2mtech released this
· 6 commits to master since this release
Choose a tag to compare

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.
a. →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.
b. →M does not perform setOperand.
c. Touching M should setOperand(variable: “M”) in the brain and then show the
result of calling evaluate in the display.
d. →M and M are Controller mechanics, not Model mechanics (though they both use
the Model mechanic of variables).
e. 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