CS 1054: Lab 2

Lab meeting 2: Understanding class definitions

This lab is supposed to help reinforce the concepts about the internals of a class.

List of tasks

  1. Make a directory on the Z: drive with your university pid as the name. Download the lab2.zip file, unzip it on the Z: drive. This should unzip two projects to the Z: drive: better-ticket-machine and lab-classes.
  2. Open the BlueJ environment. This can be done by clicking on Start -> BlueJ or Start -> All Programs -> BlueJ -> BlueJ.
  3. You might want to have a copy of the Chapter 2 notes open in another window (Press Shift+Click to open in another window).
  4. Open the better-ticket-machine project from the Z: drive by clicking on Project -> Open Project. You should see a single rectangle on the screen representing the TicketMachine class. Comppile the class by right-clicking on the rectangle and selecting compile on the menu. Note: For more detailed instructions on using the BlueJ environment, you can refer to the BlueJ tutorial (Shift + Click to open it in another window).
  5. Experiment with this class that we went over in class by creating objects and invoking the various methods associated with each object. Create different objects from the same class by initializing the class with different ticket prices.
  6. Double click on the class to open a new window that displays the associated source code.
  7. Examine the refundBalance method to see how it works. Invoke this method in the objects that you created after you inserted some money in the ticket machine using the insertMoney method. Comment out the existing code present in the body of the refundBalance method. Do the tasks mentioned in Exercises 2.34 and 2.35 after you comment the code. Examine the error messages displayed when you perform Exercise 2.35. Write down the error message on a sheet of paper.
  8. Do the tasks mentioned in Exercises 2.36, 2.37 and 2.38.
  9. Close the better-ticket-machine project and open the lab-classes project. Perform exercises 2.40 and 2.41. Write down the answer to exercise 2.41.
  10. Do the tasks mentioned in Exercises 2.42 and 2.43. Demonstrate your working version to the GTA.

© Mir Farooq Ali 2003.