123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
-
- public class TicketMachine
- {
-
- private int price;
-
- private int balance;
-
- private int total;
-
- private int score;
- /**
- * Create a machine that issues tickets of the given price.
- * Note that the price must be greater than zero, and there
- * are no checks to ensure this.
- */
- public TicketMachine()
- {
- price = 1000;
- balance = 0;
- total = 0;
- }
-
- public TicketMachine(int ticketCost){}
-
-
- public void setPrie(int ticketCost){
- price = ticketCost;
- }
-
-
- public int getPrice()
- {
- return price;
- }
-
- /**
- * Return the amount of money already inserted for the
- * next ticket.
- */
- public int getBalance()
- {
- return balance;
- }
-
- public void increase(int points){
- score = score + points;
- }
-
- public void discount(int amount){
-
- price = price - amount;
- }
-
- public void promot(){
- System.out.println("Please insert the correct amount of money.");
- }
-
- public void showPrice(){
- System.out.println("The price of a ticke is" + price + "cents");
- }
-
- /**
- * Receive an amount of money in cents from a customer.
- */
- public void insertMoney(int amount)
- {
- balance = balance + amount;
- }
-
- public int getTotal(int amount){
- return total;
- }
-
- public void empty(){
- total = 0;
- }
-
- /**
- * Print a ticket.
- * Update the total collected and
- * reduce the balance to zero.
- */
- 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;
- }
- }
|