Source of CashDispenser.java


  1: // CashDispenser.java
  2: // Represents the cash dispenser of the ATM
  3: 
  4: public class CashDispenser 
  5: {
  6:    // the default initial number of bills in the cash dispenser
  7:    private final static int INITIAL_COUNT = 500;
  8:    private int count; // number of $20 bills remaining
  9:    
 10:    // no-argument CashDispenser constructor initializes count to default
 11:    public CashDispenser()
 12:    {
 13:       count = INITIAL_COUNT; // set count attribute to default
 14:    } // end CashDispenser constructor
 15: 
 16:    // simulates dispensing of specified amount of cash
 17:    public void dispenseCash( int amount )
 18:    {
 19:       int billsRequired = amount / 20; // number of $20 bills required
 20:       count -= billsRequired; // update the count of bills
 21:    } // end method dispenseCash
 22: 
 23:    // indicates whether cash dispenser can dispense desired amount
 24:    public boolean isSufficientCashAvailable( int amount )
 25:    {
 26:       int billsRequired = amount / 20; // number of $20 bills required
 27: 
 28:       if ( count >= billsRequired  )
 29:          return true; // enough bills available
 30:       else 
 31:          return false; // not enough bills available
 32:    } // end method isSufficientCashAvailable
 33: } // end class CashDispenser
 34: 
 35: 
 36: 
 37: /**************************************************************************
 38:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 39:  * Pearson Education, Inc. All Rights Reserved.                           *
 40:  *                                                                        *
 41:  * DISCLAIMER: The authors and publisher of this book have used their     *
 42:  * best efforts in preparing the book. These efforts include the          *
 43:  * development, research, and testing of the theories and programs        *
 44:  * to determine their effectiveness. The authors and publisher make       *
 45:  * no warranty of any kind, expressed or implied, with regard to these    *
 46:  * programs or to the documentation contained in these books. The authors *
 47:  * and publisher shall not be liable in any event for incidental or       *
 48:  * consequential damages in connection with, or arising out of, the       *
 49:  * furnishing, performance, or use of these programs.                     *
 50:  *************************************************************************/