Source of PiggyBank.java


  1: // NOTE: We have substituted the class ArrayBag from Chapter 2
  2: // for the class Bag that is used in Chapter 1.
  3: /**
  4:     A class that implements a piggy bank by using a bag.
  5:     @author Frank M. Carrano
  6:     @author Timothy M. Henry
  7:     @version 5.0
  8: */
  9: public class PiggyBank
 10: {
 11:         private BagInterface<Coin> coins;

 13:         public PiggyBank() 
 14:         {
 15:                 coins = new ArrayBag<>();
 16:         } // end default constructor

 18:         public boolean add(Coin aCoin) 
 19:         {
 20:                 return coins.add(aCoin);
 21:         } // end add

 23:         public Coin remove() 
 24:         {
 25:                 return coins.remove();
 26:         } // end remove

 28:         public boolean isEmpty() 
 29:         {
 30:                 return coins.isEmpty();
 31:         } // end isEmpty
 32: } // end PiggyBank