rahajengdwp

Untitled

Mar 4th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. //Untuk Class TicketMachine
  2.  
  3. public class TicketMachine
  4. {
  5. // The price of a ticket from this machine.
  6. private int price;
  7. //The amount of money entered by a customer so far.
  8. private int balance;
  9. // The total amount of money collected by this machine.
  10. private int total;
  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