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. This version has no output to the console window other than the printing of the ticket.

Version:
2005.03.01
Author:
David J. Barnes and Michael Kolling, John Pagliarulo

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 Total is reset to 0
 int getBalance()
           
 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()
          Gives change to the user Balance is reset to 0
 
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 Total is reset to 0

Returns:
the total amount of money in the machine

getBalance

public int getBalance()
Returns:
The amount of money inserted for the ticket.

getPrice

public int getPrice()
Returns:
The price of a ticket.

insertMoney

public void insertMoney(int amount)
Receive an amount of money in cents from a customer. If amount is <= 0 it is ignored.


printTicket

public void printTicket()
Print a ticket if enough money has been inserted, and reduce the current balance by the ticket price.


refundBalance

public int refundBalance()
Gives change to the user Balance is reset to 0

Returns:
the balance of money in the machine