Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class TicketMachine
  2. {
  3. private int price;
  4. private int balance;
  5. private int total;
  6.  
  7. public TicketMachine(int ticketCost)
  8. {
  9. price = ticketCost;
  10. balance = 0;
  11. total = 0;
  12. }
  13. /**
  14. * Return the price of a ticket.
  15. */
  16. public int getPrice()
  17. {
  18. return price;
  19. }
  20.  
  21. public int getBalance()
  22. {
  23. return balance;
  24. }
  25. /**
  26. * Receive an amount of money in cents from a customer.
  27. */
  28. public void insertMoney(int amount)
  29. {
  30. balance = balance + amount;
  31. }
  32.  
  33. public void printTicket()
  34. {
  35. System.out.println("##################");
  36. System.out.println("# The BlueJ Line");
  37. System.out.println("# Ticket");
  38. System.out.println("# " + price + " rupiah.");
  39. System.out.println("##################");
  40. System.out.println();
  41. total = total + balance;
  42. balance = 0;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement