Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Edit RollOverCounter, as follows: the statement public class RollOverCounter so that this class is now a subclass of Counter. Delete all fields and constants. Don't

Edit RollOverCounter, as follows: the statement public class RollOverCounter so that this class is now a subclass of Counter. Delete all fields and constants. Don't change the constructors. Delete all methods except countUp(). Comment out countUp() (e.g., put // in front of the method declaration and every statement in the method body).
Verify that your RollOverCounter class has no fields and constants, two constructors, and one commented-out method (countUp()).
Compile RollOverCounter. What error message to you see? What caused this error?
Edit the RollOverCounter constructors so that they use super() to invoke the constructor in class Counter. Remember, super() can be called without parameters, or it can be called with a parameter list. For each constructor, pick the most appropriate form of super(). Edit and compile your class until it compiles without errors. countUp() should remain commented out.

Interactively create the RollOverCounter object. By default, the counter counts between 0 and 999. When the count is 999 and the count-up button is pressed, the count "rolls over" to 0.

Remove the //'s from the front of the statements in countUp() method,rewrite countUp(). When the count is at its maximum value, counting up should cause the count to roll over to its minimum value.When doing this step, do not modify class Counter. Remember that inherited methods can be invoked using internal method calls.

Class Counter

public class Counter
{
/** The current value of this counter. */
private int count;

/** The minimum value of this counter. */
private int minimumCount;

/** The maximum value of this counter. */
private int maximumCount;

/** The default minimum value of this counter. */
private static final int DEFAULT_MINIMUM = 0;

/** The default maximum value of this counter. */
private static final int DEFAULT_MAXIMUM = 999;

/**
* Constructs a new RollOverCounter whose current count is
* initialized to DEFAULT_MINIMUM, and which counts between
* DEFAULT_MINIMUM and DEFAULT_MAXIMUM, inclusive.
*/
public Counter()
{
minimumCount = DEFAULT_MINIMUM;
maximumCount = DEFAULT_MAXIMUM;
count = minimumCount;
}

/**
* Constructs a new RollOverCounter whose current count is
* initialized to minCount, and which counts between
* minCount and maxCount, inclusive.
*/
public Counter(int minCount, int maxCount)
{
minimumCount = minCount;
maximumCount = maxCount;
count = minimumCount;
}

/**
* Returns the maximum value of this counter.
*/
public int maximumCount()
{
return maximumCount;
}

/**
* Returns the minimum value of this counter.
*/
public int minimumCount()
{
return minimumCount;
}

/**
* Returns this counter's current count.
*/
public int count()
{
return count;
}

/**
* Returns true if this counter is at its minimum value.
*/
public boolean isAtMinimum()
{
return (count == minimumCount);
}

/**
* Returns true if this counter is at its maximum value.
*/
public boolean isAtMaximum()
{
return (count == maximumCount);
}

/**
* Resets this counter to its minimum value.
*/
public void reset()
{
count = minimumCount;
}

/**
* Increment this counter by 1.
*/
public void incrementCount()
{
count++;
}
}

Class PollOverCounter

public class RollOverCounter
{
/** The current value of this counter. */
private int count;

/** The minimum value of this counter. */
private int minimumCount;

/** The maximum value of this counter. */
private int maximumCount;

/** The default minimum value of this counter. */
private static final int DEFAULT_MINIMUM = 0;

/** The default maximum value of this counter. */
private static final int DEFAULT_MAXIMUM = 999;

/**
* Constructs a new RollOverCounter whose current count is
* initialized to DEFAULT_MINIMUM, and which counts between
* DEFAULT_MINIMUM and DEFAULT_MAXIMUM, inclusive.
*/
public RollOverCounter()
{
minimumCount = DEFAULT_MINIMUM;
maximumCount = DEFAULT_MAXIMUM;
count = minimumCount;
}

/**
* Constructs a new RollOverCounter whose current count is
* initialized to minCount, and which counts between
* minCount and maxCount, inclusive.
*/
public RollOverCounter(int minCount, int maxCount)
{
minimumCount = minCount;
maximumCount = maxCount;
count = minimumCount;
}

/**
* Returns the maximum value of this counter.
*/
public int maximumCount()
{
return maximumCount;
}

/**
* Returns the minimum value of this counter.
*/
public int minimumCount()
{
return minimumCount;
}

/**
* Returns this counter's current count.
*/
public int count()
{
return count;
}

/**
* Returns true if this counter is at its minimum value.
*/
public boolean isAtMinimum()
{
return (count == minimumCount);
}

/**
* Returns true if this counter is at its maximum value.
*/
public boolean isAtMaximum()
{
return (count == maximumCount);
}

/**
* Resets this counter to its minimum value.
*/
public void reset()
{
count = minimumCount;
}

/**
* Increment this counter by 1.
*/
public void countUp()
{
// If we've reached the maximum count, invoking this
// method rolls the counter over to its minimum value.
if (count == maximumCount) {
count = minimumCount;
} else {
count++;
}
}
}

Step by Step Solution

3.42 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

Your updated RollOverCounterjava class public class RollOverCounter extends Counter Constructs a new RollOverCounter whose current count is initialize... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Accounting

Authors: Timothy Doupnik, Hector Perera

4th edition

77862201, 978-0077760298, 77760298, 978-0077862206

More Books

Students also viewed these Programming questions

Question

1. Describe the structure of language.

Answered: 1 week ago