Question
Please do it in JAVA!!! Thank you. DIRECTIONS: Counter The skeleton of the Counter class already exists and is in Counter.java. Test code has been
Please do it in JAVA!!! Thank you.
DIRECTIONS:
Counter
The skeleton of the Counter class already exists and is in Counter.java. Test code has been created and is inCounterTest.java. You will complete the methods for the Counterclass.
Step 1. If you have not done so, look at the interface documentation in Counter.html. Look at the skeleton in Counter.java. All of the methods exist, but do not do anything yet. Compile the classes CounterInitializationException, Counter, and CounterTest. Run the main method in CounterTest.
Checkpoint: If all has gone well, you should see test results. Don't worry for now about whether the test cases indicate pass or fail. All we want to see is that the Counter class has the correct protocol. Again we will work from the heart of the class outward. Your first task is to complete the constructors.
Step 2. Create private data fields that will hold the state of a Counter object. Step 3. Complete the default constructor. It should create a counter with a minimum of 0 and a maximum
that is the largest possible integer value (Integer.MAX_VALUE). Step 4. Complete the alternate constructor. It should check to see if the minimum value is less than the
maximum value and throw an exception if not.
Checkpoint: At this point we will verify that the exception is correctly generated. Your code should compile and pass all the tests in testConstructor(). If it fails any tests, debug and retest. This is not a complete test of the constructors and you may have to revise them. The toString() method is useful to implement early because it reports on the state of an object without changing it. It can then be used in later test cases. It is also one of the methods that classes typically override.
Step 5. Complete the method toString().
Checkpoint: Your code should compile. There is no mandated format for your toString() method. Check that it produces all the information given by the print statements in testToString. If not, debug and retest. Another method that is typically overridden is the equals() method. You will work with it next.
Step 6. Complete the method equals(). It has been started for you and will test to make sure that the other object is of the same type. Complete the then clause of the if statement to check that all the private state data fields have the same value.
Checkpoint: Your code should compile and pass all the tests through testEquals(). If it fails any tests, debug and retest. There are two final accessor methods to complete and then the mutators will be implemented.
Lab Manual for Data Structures and Abstractions with Java TM 9
Step 7. Complete the method value().
Step 8. Complete the method rolledOver().
Step 9. Complete the method increase().
Check point: Your code should compile and pass all the tests through testIncrease(). If it fails any tests, debug and retest. This is really the first test that exercises a major portion of the responsibilities of the Counter class. Up until now the state of the class should not have been affected by the methods. We use the accessors to test the state of the object after the mutator has been called.
Step 10. Complete the method decrease().
Checkpoint: Your code should compile and pass all the tests. The tests in testDecrease() are similar to what you have seen before. The decrease mutator is applied and the state is queried using the accessors. There is a different style of test being performed by testCombined(). It tests to see if the increase and decrease mutators are inverses of one another. Most of the time an increase followed by a decrease should leave the object in its original state.
---------COUNTER SKELETON CODE:------Fill it in. Also there are 2 other class that goes with counter to run it (They are already done)! Just need to fill out counter and test if it passes- Thank you
/**
* The counter class implements a counter that will roll over to the
initial
* value when it hits the maximum value.
*
* @author Charles Hoot
* @version 4.0
*/
public class Counter
{
// PUT PRIVATE DATA FIELDS HERE
/**
* The default constructor for objects of class Counter. Minimum is
0 and the maximum
* is the largest possible integer.
*/
public Counter()
{
// ADD CODE FOR THE CONSTRUCTOR
}
/**
* The alternate constructor for objects of class Counter. The
minimum and maximum values are given as parameters.
* The counter starts at the minimum value.
* @param min The minimum value that the counter can have
* @param max The maximum value that the counter can have
* */
public Counter(int min, int max)
{
// ADD CODE FOR THE ALTERNATE CONSTRUCTOR
}
/**
* Determine if two counters are in the same state
*
* @param otherObject the object to test against for equality
* @return true if the objects are in the same state
*/
public boolean equals(Object otherObject)
{
boolean result = true;
if (otherObjectinstanceof Counter)
{
// YOUR CODE GOES HERE
}
return result;
}
/**
* Increases the counter by one
*/
public void increase()
{
// ADD CODE TO INCREASE THE VALUE OF THE COUNTER
}
/**
* Decreases the counter by one
*/
public void decrease()
{
// ADD CODE TO INCREASE THE VALUE OF THE COUNTER
}
/**
* Get the value of the counter
*
* @return the current value of the counter
*/
publicint value()
{
// CHANGE THE RETURN TO GIVE THE CURRENT VALUE OF THE COUNTER
return -50;
}
/**
* Accessor that allows the client to determine if the counter
* rolled over on the last count
*
* @return true if the counter rolled over
*/
public boolean rolledOver()
{
// CHANGE THE RETURN TO THE ROLLOVER STATUS OF THE COUNTER
return true;
}
/**
* Override the toString method to provide a more informative
* description of the counter
*
* @return a descriptive string about the object
*/
public String toString()
{
// CHANGE THE RETURN TO A DESCRIPTION OF THE COUNTER
return "";
}
}
VERY IMPORTANT CODE BELOW!!!!
https://codeshare.io/alxRLy <-------CounterTest.java
https://codeshare.io/ayYRX9 <---------CounterInitializationException
^ Those code are already done you need these two classes to run Counter
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started