Smileys at the Races

Lab Assignment 3
to prepare for Lab Exam 3

In this assignment you write a program where smileys run a race and, at race’s end, shows statistics about the racers’ running times. The assignment gives you practice with simple uses of ArrayLists and additional practice with boolean expressions, if statments, loops and nested structures.


Program Behavior and General Requirements

This program begins with smiley racers, on the left edge of the graphics display, facing right; we see them in profile. They each have a name displayed, in color, in the middle of their faces, so we can root for our favorite.

The race begins when the user presses the Go! button; these racers then begin moving to the right. When a smiley hits the right wall, it’s completed a lap. The smiley then reverses direction (so that it is facing left), its speed is adjusted (as discussed below), and it heads for the left wall. When it hits the left wall, again the profile and direction are reversed, the speed is again adjusted, and the racer heads for the right wall; another lap has been completed. As the race is run, the number of laps a smiley has completed so far is displayed next to its name.

When a racer completes the race—that is, runs the number of laps that constitue a race—the smiley stops. When all racers finish the race, the “stats” box at the bottom of the window shows the name and time of the fastest racer, the name and time of the slowest racer, and the average of all the racers’ times.

The program then stops; the window remains open so the user can read the statistics. The user clicks on the close box to close the window and end the program; if the close box is clicked while the race is still running, the program still shuts down.


Technical Details

For this assignment, we’ve again helped you get started by providing a significant amount of code and lots of comments and documentation. All your work is done in the SmileyAnimation and SmileyRacer classes. We’ve provided several classes in compiled form; three of them (SmileyFace, SmileyFacePart, and SmileyDisplay) have public methods and constants that you may need, so we’ve included text files describing each of them. Note that SmileyFace and SmileyFacePart as the same as they were in Lab 2; we explain why below.

Some additional technical details:

As before, all the class and Java source files you need have been placed into an Eclipse project and zipped into an archive; download 21Lab3.zip to get it. Using the same procedure that you followed previously, import this project into your Eclipse workspace.

Do remember to test your program incrementally, as described in Assignment 2; it will very likely save you a lot of time and frustration!


About Lab Exam 3

Lab exam 3 will be very similar, but perhaps not identical, to the program you are to write for this assognment. You will be asked to code one or more of the following methods:

From the SmileyAnimation class:

From the SmileyRacer class:

Remember to read over INSTRUCTIONS!.txt and program comments before beginning; they will tell you what you are to complete.

Also recall that a significant failure to follow class style standards on a lab exam can result in a “not pass” for that exam. In particular, do not use a break statement other than as the last line of a case block in a switch statement.


Written by Norman Jacobson for ICS 21 Fall 2006, October 2006.
Revised by Norman Jacobson to explain how to set the smile properly and to discuss the Go button, November 2006.
Minor editing for clarity, by Norman Jacobson, December 2006, September 2008.
Updated to reflect use of Eclipse by Norman Jacobson, September 2009.
  Includes some text adapted from Alex Thornton's "Lab 3" for ICS 21 Summer 2009.
Minor edits, by Norman Jacobson, September 2010.
Updated to discuss use of getLeftEdge(), by Norman Jacobson, December 2010.