Class Counter

java.lang.Object
  extended by Counter

public class Counter
extends java.lang.Object

Class to represent an integer counter.

COMP 1600, Project 3, Spring 2014.


Field Summary
static int MINIMUM
          Minimum value of the counter (0).
 
Constructor Summary
Counter(int max)
          Create Counter with initial value MINIMUM and specified maximum.
Counter(int count, int max)
          Create Counter with specified initial value and maximum.
 
Method Summary
 void decrement()
          Decrement counter value.
 int getCount()
          Retrieve current counter value.
 void increment()
          Increment counter value.
 boolean isAtMaximum()
          Test whether or not counter is at maximum value.
 boolean isAtMinimum()
          Test whether or not counter is at minimum value (MINIMUM).
 void reset()
          Reset counter to MINIMUM.
 java.lang.String toString()
          Produce and return String representation of counter value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM

public static final int MINIMUM
Minimum value of the counter (0).

See Also:
Constant Field Values
Constructor Detail

Counter

public Counter(int count,
               int max)
Create Counter with specified initial value and maximum.

Parameters:
count - Initial value. MINIMUM <= count <= max
max - Maximum value of the counter.

Counter

public Counter(int max)
Create Counter with initial value MINIMUM and specified maximum.

Parameters:
max - Maximum value of the counter.
Method Detail

increment

public void increment()
Increment counter value. Will not increment if counter is already at maximum.


decrement

public void decrement()
Decrement counter value. Will not decrement if counter is already MINIMUM.


getCount

public int getCount()
Retrieve current counter value.

Returns:
current counter value

reset

public void reset()
Reset counter to MINIMUM.


toString

public java.lang.String toString()
Produce and return String representation of counter value.

Overrides:
toString in class java.lang.Object
Returns:
String representation of counter value

isAtMaximum

public boolean isAtMaximum()
Test whether or not counter is at maximum value.

Returns:
true if counter is at maximum value, false otherwise.

isAtMinimum

public boolean isAtMinimum()
Test whether or not counter is at minimum value (MINIMUM).

Returns:
true if counter is at minimum value (MINIMUM), false otherwise.