## Class TicketMachine

- java.lang.Object
- - TicketMachine

    public class TicketMachine
    extends java.lang.Object

TicketMachine models a naive ticket machine that issues flat-fare tickets. The price of a ticket is specified via the constructor. It is a naive machine in the sense that it trusts its users to insert enough money before trying to print a ticket. It also assumes that users enter sensible amounts.

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

### Constructor Summary

Constructors
Constructor and Description
`TicketMachine(int ticketCost)` Create a machine that issues tickets of the given price.

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `getBalance()` Return the amount of money already inserted for the next ticket.
`int` `getPrice()` Return the price of a ticket.
`void` `insertMoney(int amount)` Receive an amount of money in cents from a customer.
`void` `printTicket()` Print a ticket.

### 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. Note that the price must be greater than zero, and there are no checks to ensure this.

### Method Detail

#### getBalance

    public int getBalance()

Return the amount of money already inserted for the next ticket.

#### getPrice

    public int getPrice()

Return the price of a ticket.

#### insertMoney

    public void insertMoney(int amount)

Receive an amount of money in cents from a customer.

#### printTicket

    public void printTicket()

Print a ticket. Update the total collected and reduce the balance to zero.