1  /**
  2     A simulated cash register that tracks the item count and
  3     the total amount due.
  4   */
  5  public class CashRegister
  6  {
  7     private int itemCount;
  8     private double totalPrice;
  9  
 10     /**
 11        Constructs a cash register with cleared item count and total.
 12     */
 13     public CashRegister()
 14     {
 15        itemCount = 0;
 16        totalPrice = 0;
 17     }
 18  
 19     /**
 20        Adds an item to this cash register.
 21        @param price the price of this item
 22     */
 23     public void addItem(double price)
 24     {
 25        itemCount++;
 26        totalPrice = totalPrice + price;
 27     }
 28  
 29     /**
 30        Gets the price of all items in the current sale.
 31        @return the total amount
 32     */
 33     public double getTotal()
 34     {
 35        return totalPrice; 
 36     }
 37     
 38     /**
 39        Gets the number of items in the current sale.
 40        @return the item count
 41     */
 42     public int getCount()
 43     {
 44        return itemCount; 
 45     }
 46  
 47     /**
 48        Clears the item count and the total.
 49     */
 50     public void clear()
 51     {
 52        itemCount = 0;
 53        totalPrice = 0;
 54     }
 55  }
 56  
 57