BlueJ - The Ticket Machine

The Ticket Machine

Download: The Ticket Machine

Review: The Ticket Machine Presentation

Introductory Assignment

Exercise 1

In BlueJ

      • Check Show Terminal.

    1. In Terminal Window:

        • Click Options

      • Check Record method calls.

    1. Create an instance of the class using TicketMachine(ticketCost) constructor.

      • Supply an int parameter for the ticketCost in cents for $1.00.

    1. Complete Exercise 2.1-2.4 on page 18 of the text.

      1. Exercise 2.1

        1. Try the getPrice method.

            • What does it do?

          • What is the return class?

        1. Insert some money and check the balance using methods:

            • insertMoney

          • getBalance

        1. Inspect the object.

        2. Insert more money that a ticket costs.

      1. Call method printTicket.

      2. Exercise 2.2

        • Check the balance.

        • What is the balance after printTicket method is called?

      • Is that reasonable?

      1. 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?

      1. 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: