You will write a 4 function calculator without using any control flow, meaning you cannot write any code that will be executed conditionally. Instead, you will apply object-orientation programming approaches to make decisions based on types instead of values. Specifically, you are expected to use the state pattern to complete this assignment.
The following are banned in your submissions:
if
/else if
/else
switch
/case
throw
/try
/catch
/finally
(Can be used to simulate conditionals)for
while
do
/while
If your submission, including your tests, contains any of the keywords listed above, it will not be graded.
GitHub Repository link: https://github.com/jessehartloff/AO2
You can run the calculator.view.CalculatorGUI
class to see the provided GUI. Your goal is to add
functionality to this GUI by implementing the calculator.model.Calculator
class.
Do not edit any code in the view
or controller
packages.
You have full control over the model
package and this is where you will write all of your code. You
may add any methods, variables, objects, classes, interfaces, or sub-packages you’d like to complete the
objectives.
All testing, including your tests, will only access the calculator.model.Calculator
class and will
only call methods provided in the Calculator
class. You may add more methods/variables/classes/etc,
but do
not access them from your tests since they will not exist in my solutions on Autolab.
Test and implement basic functionality for your calculator to earn the first application objective
Test the following features of your calculator.model.Calculator
class. In your tests, only call the
methods that are provided in the handout code as any other methods.variables.classes won't exist
in the solutions and will cause errors in Autolab. You will call the various
"pressed" methods to simulate pressing buttons on the calculator, then call displayNumber
and
assert that it returns the expected value.
For this application objective, test the following functionality in the tests.TestCalculator
class:
displayNumber()
returning 461.0.
When testing the number buttons, only call the numberPressed
method with an input in the
range 0-9. These are the only inputs that the GUI can call the method with and all others
should be considered invalid and should not be tested
displayNumber()
should return 5.0
You'll need to append digits to the end of numbers and also display them as Doubles
. It can help to
store
the numbers as both Strings
and doubles
to build this functionality. When a digit is pressed,
concatenate
the digit to the end of the String
, then convert the String
to a double
and store this separately for the
displayNumber
method. (Or convert the String
to a double
in the displayNumber
method)
Implement the tested functionality without using any control flow
Test and implement advanced functionality for your calculator to earn the second application objective
For this application objective, test the following functionality in the tests.TestCalculator
class:
Implement the tested functionality without using any control flow
To limit the complexity of this assignment there are certain sequences of button presses that have undefined behaviour. These sequences will not be tested in Autolab and you must not test these sequences in your tests since the expected number to be displayed is undefined. Do not test any of the following:
displayNumber
is when the first
number is being entered or immediately after the = button is pressed