// Filename Counters/WarningCounter.java. // Providing a non-abstract counter class with // warning behaviour. // // Written for JFL book Chapter 3 see text. // Fintan Culwin, v0.1, January 1997 // // Added the implementation of void print() to avoid a compliant by the javac // (jdk1.4) // Xiannong Meng // aug-14-2003 // package CountersPkg; import java.io.*; import CountersPkg.CounterException; public class WarningCounter extends LimitedCounter { public WarningCounter() { super(); } // End default Constructor. public WarningCounter( int minToCount, int maxToCount) { super( minToCount, maxToCount); } // End principal Constructor. public void count() { if ( this.isAtMaximum()) { throw new CounterException( "Attempt to count beyond limit."); } else { super.count(); } } // End count. public void unCount() { if ( this.isAtMinimum()) { throw new CounterException( "Attempt to count below limit."); } else { super.unCount(); } } // End unCount. // print public void print() { System.out.println(" Value of the counter " + numberCountedIs()); } // toString public String toString() { return " " + this.numberCountedIs() + " "; } } // End WarningCounter