/* ResetableCounter.java ** Java class that extends Counter by adding a method reset() by which a ** counter's value can be changed back to its value at construction. ** ** Author: R. McCloskey */ public class ResetableCounter extends Counter { // instance variable // ----------------- private int initVal; // "remembers" this Counter's initial value // constructors // ------------ /* Initializes this ResetableCounter to have the specified count value. */ public ResetableCounter(int initCntrVal) { super(initCntrVal); initVal = initCntrVal; } /* Initializes this ResetableCounter to have zero as its count value. */ public ResetableCounter() { this(0); } // observer // -------- /* Returns this ResetableCounter's initial count value. */ public int initialVal() { return initVal; } // mutator // ------- /* Sets this ResetableCounter's count value back to its original value. */ public void reset() { this.setTo(initVal); } }