Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Untuk Class TicketMachine
- public class TicketMachine
- {
- // The price of a ticket from this machine.
- private int price;
- //The amount of money entered by a customer so far.
- private int balance;
- // The total amount of money collected by this machine.
- private int total;
- public TicketMachine (int ticketCost)
- {
- price=ticketCost;
- balance=0;
- total=0;
- }
- public int getPrice()
- {
- return price;
- }
- public int getBalance()
- {
- return balance;
- }
- public void insertMoney(int amount)
- {
- balance=balance+amount;
- }
- public void printTicket()
- {
- // Simulate the printing of a ticket.
- System.out.println("##################");
- System.out.println("# The BlueJ Line");
- System.out.println("# Ticket");
- System.out.println("# " + price + " cents.");
- System.out.println("##################");
- System.out.println();
- // Update the total collected with the balance.
- total=total+balance;
- // Clear the balance.
- balance=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment