class CounterTest { public static void main(String[] args) { Counter c1 = new Counter(100); System.out.println(c1.getValue()); for (int i = 1; i <= 99; i++) c1.click(); System.out.println(c1.getValue()); c1.click(); System.out.println(c1.getValue()); c1.click(); c1.click(); System.out.println(c1.getValue()); c1.reset(); System.out.println(c1.getValue()); } // end of main() } // end of class CounterTest class Counter { private int value; private int limit; public Counter(int limit) { // constructor this.limit = limit; // note use of this value = 0; } public int getValue() { return value; } public void click() { value = (value + 1) % limit; } public void reset() { value = 0; } } // end of class Counter