A class providing for providing objects with integer calculator functionality
- Requirements
- Keep track of a running total.
- Default constructor that starts off the running total to 0.
- Specific constructor that starts off the running total to a specified value.
- An inspector for accessing the running total.
- Add, subtract, multiply, and divide capabilities
- Reset running total to 0
- Set the running total of the calculator to a specified value
- Produce a String representation upon request
- Test whether the calculator has the same running total of another calculator
- Duplicate a calculator
- Decisions
- How should the running be represented?
- What would be appropriate method names?
- Public requirements
- Calculator()
- Sets the running total of the calculator to 0
- Calculator( int startValue )
- Sets the running total of the calculator to startValue
- void set( int n )
- Sets the running total of the calculator to n
- void add( int n )
- Increments the running total of the calculator by n
- void subtract( int n )
- Decrements the running total of the calculator by n
- void multiply( int n )
- Scales the running total by n
- void divide( int n )
- If n is nonzero then reduces the running total of the calculator by factor 1/n
- void reset()
- Sets the running total of the calculator to 0
- int value()
- Supplies the current value of the running total of the calculator
- String toString()
- Produces a text representation of the running total of the calculator
- boolean equals( Object v )
- If v is a Calculator then returns whether the calculator and the v calculator have the same running totals
- Object clone()
- Produce a new calculator that duplicates the calculator
- Non-public requirements
- int runningTotal
- Attribute maintaining the current runningTotal of the calculator
- Implementation
- Testing
- What would be a reason tester for your Calculator implementation?
- Make CalculatorTester.java a reasonable test program
- Requirements
- Default constructor -- has the attributes all being 0
- Attributes represented as a three element int array named value
- ?
- Develop a class called Triple for representing three integer nonnegative values.
- Your personal antennae should go up given the requirement that a Triple object store nonnegative values. This requirement indicates that Triple mutators must check a value before using it to update a Triple object.
- Calculator
- DNA
- Classes