Class TicketMachine

java.lang.Object
  extended byTicketMachine

public class TicketMachine
extends java.lang.Object

TicketMachine models a ticket machine that issues flat-fare tickets. The price of a ticket is specified via the constructor. Instances will check to ensure that a user only enters sensible amounts of money, and will only print a ticket if enough money has been input.

Version:
2003.12.01
Author:
David J. Barnes and Michael Kolling

Constructor Summary
TicketMachine(int ticketCost)
          Create a machine that issues tickets of the given price.
 
Method Summary
 int emptyMachine()
          Empty the money in the machine The amount of money is returned
 int getBalance()
          Return The amount of money already inserted for the next ticket.
 int getPrice()
           
 void insertMoney(int amount)
          Receive an amount of money in cents from a customer.
 void printTicket()
          Print a ticket if enough money has been inserted, and reduce the current balance by the ticket price.
 int refundBalance()
          Return the money in the balance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TicketMachine

public TicketMachine(int ticketCost)
Create a machine that issues tickets of the given price.

Method Detail

emptyMachine

public int emptyMachine()
Empty the money in the machine The amount of money is returned


getBalance

public int getBalance()
Return The amount of money already inserted for the next ticket.


getPrice

public int getPrice()

insertMoney

public void insertMoney(int amount)
Receive an amount of money in cents from a customer. Check that the amount is sensible.


printTicket

public void printTicket()
Print a ticket if enough money has been inserted, and reduce the current balance by the ticket price. Print an error message if more money is required.


refundBalance

public int refundBalance()
Return the money in the balance. The balance is cleared.