AkramAbd

Class Ticket Machine

Mar 6th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public class TicketMachine
  2. {
  3.  
  4.  
  5. private int price;
  6. // The amount of money entered by a customer so far.
  7. private int balance;
  8. // The total amount of money collected by this machine.
  9. private int total;
  10.  
  11.  
  12. public TicketMachine(int ticketCost)
  13. {
  14. price = ticketCost;
  15. balance = 0;
  16. total = 0;
  17. }
  18.  
  19. public int getPrice()
  20. {
  21. return price;
  22. }
  23.  
  24. public int getBalance()
  25. {
  26. return balance;
  27. }
  28.  
  29. public void insertMoney(int amount)
  30. {
  31. balance = balance + amount;
  32. }
  33.  
  34. public void printTicket()
  35. {
  36. // Simulate the printing of a ticket.
  37. System.out.println("##################");
  38. System.out.println("# The BlueJ Line");
  39. System.out.println("# Ticket");
  40. System.out.println("# " + price + " cents.");
  41. System.out.println("##################");
  42. System.out.println();
  43.  
  44. // Update the total collected with the balance.
  45. total = total + balance;
  46. // Clear the balance.
  47. balance = 0;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment