/* RollOverCounter.java ** Java class that extends BoundedCounter by providing concrete versions of ** incrementFromCeiling() and decrementFromFloor(). The intended behavior ** of these two is to cause the count value to "roll over" (i.e., change ** from ceiling to floor (when incrementing) and from floor to ceiling when ** decrementing). ** ** Author: R. McCloskey */ public class RollOverCounter extends BoundedCounter { // constructors // ------------ /* Initializes this RollOverCounter so that its range of possible ** count values is [min..max] and its initial count value is init. ** ** pre: min <= init <= max ** post: this.countVal() == init, ** this.floorOf() == min, ** this.ceilingOf() == max */ public RollOverCounter(int init, int min, int max) { super(init, min, max); } /* Initializes this RollOverCounter so that its range of possible ** count values is [min..max] and its initial count value is min. ** ** pre: min <= max ** post: this.countVal() == min, ** this.floorOf() == min, ** this.ceilingOf() == max */ public RollOverCounter(int min, int max) { this(min, min, max); } // observer // -------- @Override public String toString() { return "(RollOverCounter) " + super.toString(); } // mutators (concrete versions of abstract methods in parent class) // -------- /* Sets this RollOverCounter's count value to its floor. ** ** post: this.countVal() == this.floorOf() */ @Override protected void incrementFromCeiling() { setTo(floorOf()); } /* Sets this RollOverCounter's count value to its ceiling. ** ** post: this.countVal() == this.ceilingOf() */ @Override protected void decrementFromFloor() { setTo(ceilingOf()); } }