/* An instance of this class represents a counter that can be in either ** of two modes: "normal" or "reverse". In normal mode, it behaves exactly ** like an instance of its parent's class. In reverse mode, the effects ** of the increment() and decrement() methods are interchanged. (That is, ** a call to increment() results in the Counter's count value decreasing by ** one, and a call to decrement() results in the count value increasing by ** one.) ** Authors: R. McCloskey and < STUDENTS' NAMES > ** Known defects: ... */ public class ReversibleCounter extends Counter { // instance variable // ----------------- private boolean inNormalMode; // constructors // ------------ /* Initializes this ReversibleCounter so that it is in normal mode ** and its count value is the one specified. */ public ReversibleCounter(int initVal) { super(initVal); inNormalMode = true; } /* Initializes this ReversibleCounter so that it is in normal mode ** and its count value is the default, zero. */ public ReversibleCounter() { // STUB (call the other constructor) } // observers // --------- /* Reports whether or not this ReversibleCounter is in normal mode. */ public boolean inNormalMode() { return true; // STUB (No if-else statement is needed.) } /* */ @Override public String toString() { String modeStr = inNormalMode() ? "normal" : "reverse"; return super.toString() + "; mode: " + modeStr; } // mutators // -------- /* Flips this ReversibleCounter's mode from one to the other. */ public void toggleMode() { // STUB (no if-else statement is needed) } /* If in normal mode, behaves like the inherited version of increment(), ** but if in reverse mode, behaves like the inherited version of decrement(). */ @Override public void increment() { // STUB (call the inherited version of either increment() // or decrement(), whichever is appropriate) } /* If in normal mode, behaves like the inherited version of decrement(), ** but if in reverse mode, behaves like the inherited version of increment(). */ @Override public void decrement() { // STUB (same advice as in increment()) } }