Class Counter

java.lang.Object
com.zybooks.dsaj.primer.Counter

public class Counter extends Object
An integer counter that can be incremented and reset to zero.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Counter with value zero.
    Counter(int initial)
    Constructs a new Counter with given initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the current count.
    void
    Increments the count by one.
    void
    increment(int delta)
    Increments the count by the specified delta.
    void
    Returns the count to zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Counter

      public Counter()
      Constructs a new Counter with value zero.
    • Counter

      public Counter(int initial)
      Constructs a new Counter with given initial value.
      Parameters:
      initial - the initial value
  • Method Details

    • getCount

      public int getCount()
      Returns the current count.
      Returns:
      the current count
    • increment

      public void increment()
      Increments the count by one.
    • increment

      public void increment(int delta)
      Increments the count by the specified delta.
      Parameters:
      delta - the amount of the increment
    • reset

      public void reset()
      Returns the count to zero.