Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Represents the cash dispenser of the ATM
  3.  */
  4. public class CashDispenser {
  5.     // the default initial number of bills in the cash dispenser
  6.     private final static int INITIAL_COUNT = 500;
  7.     private int count; // number of $20 bills remaining
  8.  
  9.     // no-argument CashDispenser constructor initializes count to default
  10.     public CashDispenser() {
  11.         count = INITIAL_COUNT; // set count attribute to default
  12.     } // end CashDispenser constructor
  13.  
  14.     // simulates dispensing of specified amount of cash
  15.     public void dispenseCash(int amount) {
  16.         int billsRequired = amount / 20; // number of $20 bills required
  17.         count -= billsRequired; // update the count of bills
  18.     } // end method dispenseCash
  19.  
  20.     // indicates whether cash dispenser can dispense desired amount
  21.     public boolean isSufficientCashAvailable(int amount) {
  22.         int billsRequired = amount / 20; // number of $20 bills required
  23.  
  24.         if (count >= billsRequired)
  25.             return true; // enough bills available
  26.         else
  27.             return false; // not enough bills available
  28.     } // end method isSufficientCashAvailable
  29. } // end class CashDispenser