SHARE
TWEET

Untitled

a guest May 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LyyraCard {
  2.  
  3.     private double balance;
  4.  
  5.     public LyyraCard(double balanceAtStart) {
  6.         balance += balanceAtStart;
  7.     }
  8.  
  9.     public String toString() {
  10.         return "The card has " + balance + " euros";
  11.     }
  12.  
  13.     public void payEconomical() {
  14.  
  15.         balance -= 2.50;
  16.         if (balance < 0) {
  17.             balance += 2.50;
  18.         }
  19.     }
  20.  
  21.     public void payGourmet() {
  22.         balance -= 4.00;
  23.         if (balance < 0) {
  24.             balance += 4.00;
  25.         }
  26.     }
  27.  
  28.     public void loadMoney(double amount) {
  29.         if (amount >= 0) {
  30.             balance += amount;
  31.         }
  32.  
  33.         if (balance > 150) {
  34.             balance = 150;
  35.         }
  36.     }
  37.     public class Main {
  38.         public static void main(String[] args) {
  39.          
  40.         LyyraCard cardPekka = new LyyraCard(20);
  41.         LyyraCard cardBrian = new LyyraCard(30);
  42.         cardPekka.payGourmet();
  43.         cardBrian.payEconomical();
  44.         System.out.println("Pekka: " + cardPekka);
  45.         System.out.println("Brian: " + cardBrian);
  46.         cardPekka.loadMoney(20);
  47.         cardBrian.payGourmet();
  48.         System.out.println("Pekka: " + cardPekka);
  49.         System.out.println("Brian: " + cardBrian);
  50.         cardPekka.payEconomical();
  51.         cardPekka.payEconomical();
  52.         cardBrian.loadMoney(50);
  53.         System.out.println("Pekka: " + cardPekka);
  54.         System.out.println("Brian: " + cardBrian);
  55.     }
  56. }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top