Home‎ > ‎ICT Programming‎ > ‎Java‎ > ‎

BlueJ - The Ticket Machine

The Ticket Machine

Download: The Ticket Machine


Introductory Assignment 

Exercise 1

In BlueJ

  1. Open project: The Ticket Machine
  2. In BlueJ menu:
    • Click View
    • Check Show Terminal.
  3. In Terminal Window:
    • Click Options
    • Check Record method calls.
  4. Create an instance of the class using TicketMachine(ticketCost) constructor.
    • Supply an int parameter for the ticketCost in cents for $1.00.
  5. Complete Exercise 2.1-2.4 on page 18 of the text.

    Exercise 2.1

    1. Try the getPrice method.
      • What does it do?
      • What is the return class?
    2. Insert some money and check the balance using methods:
      • insertMoney
      • getBalance
    3. Inspect the object.
    4. Insert more money that a ticket costs.
    5. 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:


Comments