CSci 157 -  Labs 7 and 8

The purpose of this lab is to exercise/develop your mastery of looping, using ActiveObjects, and running from the command line.

Part 1

Pay particular attention to section 7.4 in the text.  Use the examples in Figure 7.14 and 7.15 as a guide to completing this part.

Figure 7.15 in the text draws a 'nice' brick wall (see 7.16 for a picture).  This works well, but it requires a set of constant declarations to control the size of the bricks and the wall itself.  

Create a simple class called BrickWall. This class will have a constructor which should: The begin method will draw the wall based on the information computed in the constructor.  This will work much like the method in Figure 7.15 with the following modifications:

Demonstrate your changes to the Instructor.

Part 2


  1. Download the Snow project files:  Snow, Cloud, FallingSnow, and snow.gif.  Make a new project out of these files, compile them, and test it.

  2. Spend some time reading the code in each file and getting a basic understanding of it.  Discuss it with your partner so you both have enough of a grasp of it to do the next few problems.

  3. The x-coordinate and speed of each snowflake is controlled by a single random number generator, specified in Cloud.  Modify this code so to use a second number generator to control the speed.  Experiment with a good range of possible values until you like the results.

  4. The snow image is transformed to a VisibleImage in the FallingSnow constructor.  Use the VisibleImage constructor that takes a width and height to make the snowflakes bigger or smaller.  Experiment until you get something you like.

  5. Search the Web for pictures of individual snowflakes (in GIF, JPG, or PNG format).  Select at least two, and use the getImage method to load them into your program.  Randomly select between these images when creating a new FallingSnow object.  Note: you will likely need to modify both and

  6. Demonstrate your changes to the Instructor.

The HotRods!

Hot Rodsalt rods  

Part 3.  Switch driver and observer before starting this part.
  1. Download the files and  Create and test the HotRods project.

  2. Let's improve it in two ways.  First, make each Hot Rod look as cool as you can make it within the limits imposed by the class.  You can improve the look of the side view, or change it to a top view as in the right screenshot above.  Also, rather than a plain white background, add two gray rectangles to be "lanes" for each card to race in. If you use the top view, draw in white or yellow lane markers.

  3. Now fix the placement and computation of the time taken by each car to run the 'course'.  Create and display a Jumbotron-scoreboard-style object showing the car color and time it runs the course.
  4. Make your program an application (so it can be run from the command line) by adding the following method:

      public static void main (String[] args) {
    new StartRace().startController(800, 500);
  5. Next, open a Terminal window and change the directory to the one containing your HotRod project program files.  Issue these commands:
    java StartRace
  6. Demonstrate your application to the instructor.

Part 4. Switch again.

  1. Download the files and  We looked at these in a previous lecture.

  2. Our Ball objects just bounce up and down.  Modify the Ball class so that the ball moves in both the x- and y-directions.  You'll need a new instance variable for the xspeed, and you'll need to initialize it randomly just as the yspeed variable is.

  3. Now the checkBounce condition is complicated by the fact that the ball might hit any of the four sides of the window.  Add the necessary checks and if the ball hits a 'wall' reverse the direction appropriately.  You might also consider selecting a new speed at random, remembering always to reverse it.

  4. Make this project an application just as the HotRod project is.  Demonstrate your application to the instructor.