Findryan

Untitled

Dec 9th, 2016
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class CashDispenser
  2. {
  3. // the default initial number of bills in the cash dispenser
  4. private final static int INITIAL_COUNT = 500;
  5. private int count; // number of $20 bills remaining
  6.  
  7. // no-argument CashDispenser constructor initializes count to default
  8. public CashDispenser(){
  9. count = INITIAL_COUNT; // set count attribute to default
  10. } // end CashDispenser constructor
  11.  
  12. // simulates dispensing of specified amount of cash
  13. public void dispenseCash(int amount){
  14. int billsRequired = amount / 20; // number of $20 bills required
  15. count -= billsRequired; // update the count of bills
  16. } // end method dispenseCash
  17.  
  18. // indicates whether cash dispenser can dispense desired amount
  19. public boolean isSufficientCashAvailable(int amount){
  20. int billsRequired = amount / 20;
  21.  
  22. if(count >= billsRequired){
  23. return true; // enough bills required
  24. }
  25. else{
  26. return false; // not enough bills required
  27. }
  28. } // end method isSufficientCashAvailable
  29. } // end class CashDispenser
Advertisement
Add Comment
Please, Sign In to add comment