There are two files ( Calculator.java and CalculatorTest.java) Do the following: Add comments tomultiplyBy()anddivideBy(). Submit to Web-CAT
Question:
There are two files (Calculator.javaandCalculatorTest.java)Do the following:
- Add comments tomultiplyBy()anddivideBy(). Submit to Web-CAT to ensure you get full points on style for this file.
- The test cases providedCalculatorTest.java all fail. Define the test cases for all methods provided: setValue(), clear(), addition(), subtraction(), multiplication(), division()
- By adding the comments and the code in the test cases, you should have recharged your submission energy. Now focus on fixing the bug in the code, which as stated earlier, should be fairly easy to find.
Calculator.java
This class represents a simple calculator that contains a single * integer accumulator. It provides basic methods to set/get/clear the * accumulator's value, as well as to add, subtract, multiply, and * divide. All operations leave their results in the accumulator for * further manipulation. * * @author Stephen Edwards * @version 2006.06.14 */ public class Calculator { //~ Instance/static variables ............................................. private int value; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new Calculator object with zero in the accumulator. */ public Calculator() { value = 0; } //~ Public Methods ........................................................ // ---------------------------------------------------------- /** * Retrieve the current value stored in the accumulator. * @return the accumulator's value */ public int getValue() { return value; } // ---------------------------------------------------------- /** * Sets the value of the accumulator to a new value. * @param val the new accumulator value */ void setValue(int val) { value = val; } // ---------------------------------------------------------- /** * Clears the accumulator by setting its value to zero. */ void clear() { setValue(0); }
// ---------------------------------------------------------- /** * Update the accumulator by adding a number to it. * @param val the amount to add */ void add(int val) { setValue(getValue() + val); } // ---------------------------------------------------------- /** * Update the accumulator by subtracting a number from it. * @param val the amount to subtract */ void subtract(int val) { setValue(getValue() - val); } // ---------------------------------------------------------- // add comments here void multiplyBy(int val) { setValue(getValue() * val); } // ---------------------------------------------------------- // add comments here void divideBy(int val) { setValue(getValue() % val); }
}
CalculatorTest.java
import org.junit.*; import static org.junit.Assert.*; //------------------------------------------------------------------------- /** * Test class for Calculator. * * @author Stephen Edwards * @version 2006.06.14 */ public class CalculatorTest { //~ Setup ................................................................. //~ Instance/static variables ............................................. private Calculator calc; // ---------------------------------------------------------- /** * Creates a new Calculator object with zero in the accumulator. */ @Before public void setUp() { calc = new Calculator(); } //~ Public Methods ........................................................ // ---------------------------------------------------------- /** * Check that a new calculator starts off with a zero value. */ @Test public void initial() { // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check setValue/getValue. */ @Test public void setValue() { // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check that clear returns the accumulator to zero. */ @Test public void clear()
{ // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check that add works on zero and non-zero accumulators. */ @Test public void addition() { // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check that subtract works on zero and non-zero accumulators. */ @Test public void subtraction() { // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check that multiplyBy works on non-zero accumulators. */ @Test public void multiplication() { // Add your own test actions here fail("Define your test"); } // ---------------------------------------------------------- /** * Check that divideBy works on non-zero accumulators. */ @Test public void division() { // Add your own test actions here fail("Define your test"); } }
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill