Smileys at the Races

Lab Assignment 4

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 LinkedLists, and additional practice with boolean expressions, if statments, loops, inheritance and polymorphism, and nested structures.


Pair Programming

You may pair program for this assignment, or work alone. Make this decision before you begin work on the assignment. Once you make the decision, it stands for the duration of the assignment. If you choose to pair program, you must work with the same partner for the assignment's duration.


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

All your work is done in the RacingGroup, RacingSmiley and RacingAnimation classes. Now that you know about interfaces, we use them to specify and document the public methods that are required for these classes; we also provide additional documentation via comments. Be sure the the classes you write implement these interfaces explicitly (via the appropriate phrase in the class' header).

We've also provided several classes in compiled form; for those that have public methods and constants you may need, we've included text files describing them. Note that SmileyFace and SmileyFacePart as the same as they were in Lab 2; we explain why below. The graphics coding for this program is much more involved than for previous assignments, so we provide that code to you as already-compiled class files—BasicFrame, BasicDisplay, RacingFrame and RacingDisplay.

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 Lab4.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!

...and also remember that style matters: you can lose points for poor style, in particular for poorly structured code and for a lack of, or poorly done, comments.


Deliverables

Zip up your project folder into the file SmileysAtTheRaces.zip, and turn it in via Checkmate.


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.
Revised to be a graded lab assignment and to use interfaces, for ICS 45J, Fall
  2012 by Norman Jacobson, August 2012.
Deliverables section added, by Norman Jacobson, October 2012.
Bad link repaired and minor typos fixed, by Norman Jacobson, November 2012.