Advertisement
Guest User

TicketMachine

a guest
Oct 23rd, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /**
  2.  * Program Mesin Tiket
  3.  *
  4.  * Anfasa Aliffian
  5.  * Versi 1.0
  6.  */
  7. public class TicketMachine
  8. {
  9.     private int price;
  10.     private int balance;
  11.     private int total;
  12.  
  13.     public TicketMachine(int ticketcost)
  14.     {
  15.         price = ticketcost;
  16.         balance = 0;
  17.         total = 0;
  18.     }
  19.    
  20.     public void getprice()
  21.     {
  22.         System.out.println(price);
  23.     }
  24.    
  25.     public void getbalance()
  26.     {
  27.         System.out.println(balance);
  28.     }
  29.    
  30.     public void insertmoney(int amount)
  31.     {
  32.         balance = balance + amount;
  33.         getbalance();
  34.     }
  35.    
  36.     public void printticket()
  37.     {
  38.         while(balance >= price)
  39.         {
  40.             balance = balance - price;
  41.             System.out.println("##################");
  42.             System.out.println("# The BlueJ Line #");
  43.             System.out.println("# ----TICKET---- #");
  44.             System.out.println("# Rp " + price + "\t #");
  45.             System.out.println("##################");
  46.             System.out.println();
  47.             total = total + balance;
  48.         }
  49.         getbalance();
  50.     }
  51.    
  52.     public void exitmachine()
  53.     {
  54.         total = total + balance;
  55.         balance = 0;
  56.        
  57.         System.exit(0);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement