/* An instance of this class represents a simple counter that can be ** incremented and decremented. ** Author: R. McCloskey, Sept. 2025 */ public class Counter { // instance variables // ------------------ private int cntrVal; // holds current "count value" // constructors // ------------ /* Initializes this Counter so that its count value is the value specified. */ public Counter(int initVal) { setTo(initVal); } /* Initializes this Counter so that its count value is zero (the default). */ public Counter() { this(0); } // observers // --------- /* Returns this Counter's current count value. */ public int countVal() { return cntrVal; } /* Returns a string reporting this Counter's current count value. */ public String toString() { return "count value: " + countVal(); } // mutators // -------- /* Sets this Counter's count value to the value specified. */ public void setTo(int newVal) { cntrVal = newVal; } /* Increases this Counter's count value by one. */ public void increment() { cntrVal = cntrVal + 1; } /* Decreases this Counter's count value by one. */ public void decrement() { cntrVal = cntrVal - 1; } }