BlueJ - The Ticket Machine
The Ticket Machine
Download: The Ticket Machine
Review: The Ticket Machine Presentation
Introductory Assignment
Exercise 1
In BlueJ
Open project: The Ticket Machine
In BlueJ menu:
Click View
Check Show Terminal.
In Terminal Window:
Click Options
Check Record method calls.
Create an instance of the class using TicketMachine(ticketCost) constructor.
Supply an int parameter for the ticketCost in cents for $1.00.
Complete Exercise 2.1-2.4 on page 18 of the text.
Exercise 2.1
Try the getPrice method.
What does it do?
What is the return class?
Insert some money and check the balance using methods:
insertMoney
getBalance
Inspect the object.
Insert more money that a ticket costs.
Call method printTicket.
Exercise 2.2
Check the balance.
What is the balance after printTicket method is called?
Is that reasonable?
Exercise 2.3
Experiment by inserting different amounts of money before calling printTicket method.
What is the balance after printTicket method is called?
What must happen to balance field in printTicket method?
Exercise 2.4
Experiment with the TicketMachine class before we examine in in detail.
Create another TicketMachine object with a different ticket price.
Buy and print a ticket.
Does the ticket look much the same?
Is that reasonable behavior? Why?
Sample Ticket Machine Code is available here. Do not copy & paste - type it in manually.
Assignment 1
Read: Objects First with Java - Chapter 2 (Pages 17-25)
Complete: Exercises 2.7 - 2.15 (pages 22-25)
Assignment 2
Read: Objects First with Java - Chapter 2 (Pages 26-32)
Complete: Exercises 2.16 - 2.20 (pages 27-28)
Good luck everyone!
Watch: