igede

Untitled

Nov 22nd, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.awt.Color;  
  2.  /**  
  3.   * Provide a counter for a participant in the simulation.  
  4.   * This includes an identifying string and a count of how  
  5.   * many participants of this type currently exist within  
  6.   * the simulation.  
  7.   *  
  8.   * @author Gede
  9.   * @version (22/11/2018)
  10.   */  
  11.  public class Counter  
  12.  {  
  13.    // A name for this type of simulation participant  
  14.    private String name;  
  15.    // How many of this type exist in the simulation.  
  16.    private int count;  
  17.    /**  
  18.     * Provide a name for one of the simulation types.  
  19.     * @param name A name, e.g. "Fox".  
  20.     */  
  21.    public Counter(String name)  
  22.    {  
  23.      this.name = name;  
  24.      count = 0;  
  25.    }  
  26.    /**  
  27.     * @return The short description of this type.  
  28.     */  
  29.    public String getName()  
  30.    {  
  31.      return name;  
  32.    }  
  33.    /**  
  34.     * @return The current count for this type.  
  35.     */  
  36.    public int getCount()  
  37.    {  
  38.      return count;  
  39.    }  
  40.    /**  
  41.     * Increment the current count by one.  
  42.     */  
  43.    public void increment()  
  44.    {  
  45.      count++;  
  46.    }  
  47.    /**  
  48.     * Reset the current count to zero.  
  49.     */  
  50.    public void reset()  
  51.    {  
  52.      count = 0;  
  53.    }  
  54.  }
Advertisement
Add Comment
Please, Sign In to add comment