Class Counter

java.lang.Object
  extended by Counter

public class Counter
extends java.lang.Object


Constructor Summary
Counter()
          Constructor for the Counter class, with initial value 0 and limit 12.
Counter(int limit)
          Constructor for the Counter class, with initial value 0 and given limit.
 
Method Summary
 int getValue()
          return the value of the Counter.
static void main(java.lang.String[] args)
          A main program to test the counter.
 void reset()
          Resets the value of the Counter to 0
 void set(int newValue)
          Sets the value of the Counter to newValue.
 void tick()
          Increment the value of the Counter, wrapping back to 0 when it reaches limit.
 java.lang.String toString()
          returns a String representation with at least 2 digits, padding with a leading 0 if necessary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Counter

public Counter()
Constructor for the Counter class, with initial value 0 and limit 12.


Counter

public Counter(int limit)
Constructor for the Counter class, with initial value 0 and given limit.

Parameters:
limit - - the upper bound for the counter
Method Detail

tick

public void tick()
Increment the value of the Counter, wrapping back to 0 when it reaches limit.


set

public void set(int newValue)
Sets the value of the Counter to newValue. If newValue is too large or is negative sets it to 0. (We will learn better ways to handle errors later!)

Parameters:
newValue - the value to reset the counter to

reset

public void reset()
Resets the value of the Counter to 0


getValue

public int getValue()
return the value of the Counter.

Returns:
the current value of the counter.

toString

public java.lang.String toString()
returns a String representation with at least 2 digits, padding with a leading 0 if necessary.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the counter with at least 2 digits.

main

public static void main(java.lang.String[] args)
A main program to test the counter. (Including such testing programs is a good idea!)