package username.textanalysis; /** * A very simple counter. * * @version 1.0 of April 2006 * @author Samuel A. Rebelsky */ public class Counter { // +------------------+---------------------------------------- // | Design Decisions | // +------------------+ /* (1) Counters use int fields, so they can't count to very large numbers.. */ // +--------+-------------------------------------------------- // | Fields | // +--------+ /** * The value being counted. */ int count; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Create a new counter with value 0. */ public Counter() { this.count = 0; } // Counter() /** * Create a new counter with initial value i. */ public Counter(int i) { this.count = i; } // Counter(int) // +---------+------------------------------------------------- // | Methods | // +---------+ /** * Increment the counter. */ public void increment() { ++this.count; } // increment() /** * Get the value of the counter. */ public int get() { return this.count; } // get() /** * Display as a string. */ public String toString() { return "[" + this.count + "]"; } // toString() } // class Counter