package jspexamples; /** * Keeps track of a simple integer counter. * Initialized to 0 (default constructor) * or to the initial value in the other constructor. * "step" is how far to increment each time, default is 1. * Developed as an example for SWE 642, Spring 2009 * * @author Jeff Offutt * @version 1.0 * 22-March-2009 */ public class counterBean { private int count; // Property of the bean private int step; // Internal use only /** * Default constructor initializes count to 0 and step to 1 * @author Jeff Offutt */ public counterBean () { count = 0; step = 1; } /** * Parameterized constructor allows client to define * the initial and step value for the bean. * @author Jeff Offutt */ public counterBean (int init, int step) { this.count = init; this.step = step; } /** * Increments the counter and returns the new value. * @author Jeff Offutt */ public int getCounter () { count = count+step; return (count); } /** * Resets the counter to the default value (0). * @author Jeff Offutt */ public void setCounter () { count = 0; } /** * Resets the counter to the value specified. * @author Jeff Offutt */ public void setCounter (int value) { count = value; } } // end counterBean