Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public class LyyraCard {
  2.  
  3. private double balance;
  4.  
  5. public LyyraCard(double balance) {
  6. this.balance = balance;
  7. }
  8.  
  9. public double balance() {
  10. return this.balance;
  11. }
  12.  
  13. public void loadMoney(double amount) {
  14. this.balance += amount;
  15. }
  16.  
  17. public boolean pay(double amount) {
  18. // method checks if the balance of the card is at least amount given as parameter
  19. // if not, methods returns false meaning that the card could not be used for the payment
  20. // if the balance is enough, the given amount is taken from the balance and true is returned
  21. if(balance() >= amount){
  22. this.balance -= amount;
  23. return true;
  24. }else{
  25. return false;
  26. }
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement