fork download
  1. public class TicketMachine
  2. {
  3. private int price;
  4. private int balance;
  5. private int total;
  6. private int refund;
  7. private int tickets;
  8.  
  9. public TicketMachine(int ticketCost)
  10. {
  11. price = ticketCost;
  12. balance = 0;
  13. total = 0;
  14. refund = 0;
  15. tickets = 0;
  16. }
  17.  
  18. public int getPrice()
  19. {
  20. return price;
  21. }
  22.  
  23. public void insertMoney(int amount)
  24. {
  25. if(amount > 0)
  26. {
  27. balance += amount;
  28. }
  29. else
  30. {
  31. System.out.println("Please inser a sensible amount of money");
  32. }
  33. }
  34.  
  35. public void printTicket()
  36. {
  37. if(balance > 0)
  38. {
  39. if(balance >= price)
  40. {
  41. tickets = purchaseTickets();
  42.  
  43. int i = 1;
  44.  
  45. while (i <= tickets)
  46. {
  47. System.out.println("-------------------");
  48. System.out.println("--The BlueJ Line---");
  49. System.out.println("--Ticket " + i);
  50. System.out.println("- " + price + " cents");
  51. System.out.println("-------------------");
  52.  
  53. i++;
  54. }
  55.  
  56. total += balance;
  57.  
  58. refund = refundBalance();
  59.  
  60. if(refund==0)
  61. {
  62. System.out.println("No Change Given");
  63. }
  64. else
  65. {
  66. System.out.println("Amount to refund: " +refund+ "cents");
  67. }
  68.  
  69. balance = 0;
  70. }
  71. else
  72. {
  73. System.out.println("Please inser " +(price - balance) +"more cents");
  74. }
  75. }
  76. else
  77. {
  78. System.out.println("Please insert a positive amount of money");
  79. }
  80. }
  81.  
  82. public int refundBalance()
  83. {
  84. int amountToRefund;
  85.  
  86. amountToRefund = balance - price * tickets;
  87.  
  88. balance = 0;
  89.  
  90. return amountToRefund;
  91. }
  92.  
  93. public int purchaseTickets()
  94. {
  95. int numberOfTickets;
  96.  
  97. numberOfTickets = balance / price;
  98.  
  99. return numberOfTickets;
  100. }
  101. }
  102.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class TicketMachine is public, should be declared in a file named TicketMachine.java
public class TicketMachine
       ^
1 error
stdout
Standard output is empty