CS 1054: Lab 1

Lab meeting 1: Objects and classes

This lab is supposed to introduce you to the BlueJ environment and help you understand the basic concepts of objects and classes.

List of tasks

  1. Make a directory on the Z: drive with your university pid as the name. Copy the picture and shapes subdirectories from the c:\BlueJ\examples\ directory to the directory that you just created.
  2. Open the BlueJ environment. This can be done by clicking on Start -> BlueJ or Start -> All Programs -> BlueJ -> BlueJ.
  3. Open the shapes project from the Z: drive where you just copied the directories by clicking on Project -> Open Project. You should see four rectangles on the screen. Each rectangle represents a particular class. If the shapes have diagonal stripes on them, compile them by right clicking on each shape and selecting the compile option. 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).
  4. Create multiple objects from each shape class. To create a new object, you should right click on the particular class and then select the "new" option. For example, you can create a new square object by right clicking on the square class and selecting the "new Square()" option.
  5. Experiment with the properties associated with each object by right clicking on the object (not the class) and then selecting the various methods. Move the objects around and change their colors using the appropriate methods.
  6. Inspect the properties of each object by right clicking and selecting the "Inspect" option. You can observe that if you modified the properties associated with the objects, different objects derived from the same class, will have different values for their fields.
  7. Double click on each class to open a new window that displays the source code associated with each class. You can see that each property associated with an object has a corresponding method in the source code. If you make any changes to the course code, you can observe diagonal stripes appearing on the classes in the BlueJ window. This implies that the classes need to be re-compiled. Note: Please do not make any changes to the code that might cause compilation errors.
  8. Close this project. By this point, you should be familiar with opening and closing a project in the BlueJ environment and a few other basics regarding classes and objects.
  9. Re-open the shapes project. Perform exercise 1.9 from the textbook. Use the various shapes provided to build the picture shown in Figure 1.7. Once you have finished this task, show the picture of your house to the GTA.
  10. Open the picture project. Perform exercises 1.10 and 1.11 from the textbook.
  11. If there is time remaining, perform exercises 1.13 and 1.14 from the textbook. Position the second sun to be above the roof of the hut.
  12. Show your work to the GTA.

© Mir Farooq Ali 2003.