/**
* Class ticketMachine yang mengeluarkan tiket dengan harga tetap
* Harga tiket ditentukan dengan input user
*
* @author Muhammad Naufaldillah
* @version 1 November 2020
*/
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;
/**
* Creat a machine that issues tickets at given price.
* Note that the price must be greater than zero, and there
* are no checks to ensure this.
*/
public TicketMachine(int cost)
{
price = cost;
balance = 0;
total = 0;
}
/**
* Return the price of a ticket
*/
public int getPrice()
{
return price;
}
/**
* Return the amount of money already inserted for the
* next ticket.
*/
public int getBalance()
{
return balance;
}
/**
* Receive an amount of money from a customer
*/
public void insertMoney(int amount)
{
balance = balance + amount;
}
/**
* Print a ticket
* Update the total collected
* reduce the balnce to zero.
*/
public void printTicket()
{
//Simulate the printing of a ticket
System.out.println("##################");
System.out.println("# 16th National middle school tournament Final");
System.out.println("# Ticket");
System.out.println("# " + price + " yen");
System.out.println("# Enjoy the match");
System.out.println("##################");
// Update the total collected with the balance.
total = total + balance;
// Clear the balance.
balance = 0;
}
}