CPSC 170 Program 4
Race Data
Due Monday, April 22

The local youth center holds an annual 5K race, and has asked you to help process the race results. You will be given a file that contains the race results for all runners, and should produce a listing of runners in each age group, sorted by time. You also need to produce a binary file containing this information for submittal to the Coordinator of Youth Athletics and tools to reread that file. Your format will be used to efficiently store and retrieve future race results.

Input

The raw data (entry number and finish time) is entered into a file by race workers, and is run through a database to replace entry numbers with names and ages. As a result, the file that you receive will contain time in minutes, age, and name information for each runner, space delimited, one entry per line. So a small input file might contain the following lines:
26.2 7 David Jones
25.8 15 Mary Ann Smith
22.3 17 Susan Brown
20.0 17 Mark White
29.3 10 Jane Doe
29.5 10 John Doe
33.2 6  Michael Watt

Output

Your program should produce a listing of runners by age group, sorted by time within age group. The age groups are as follows:
      7 and under
      8-10
      11-14
      15-17
Thus for the file above, you might produce the following listing:
 7 and under 
-------------
26.2  7  David Jones
33.2  6  Michael Watt

 8-10 
-------------
29.3  10  Jane Doe
29.5  10  John Doe

 11-14
-------------

 15-17
-------------
20.0 17 Mark White
22.3 17 Susan Brown
25.8 15 Mary Ann Smith

Program Structure

Your program should be organized as follows:
  1. Define a Runner class that stores information for a single runner. Since you will need to compare Runner objects (by time), this class will need to implement the Comparable interface. Since you will be writing Runner objects to a file, it will also need to implement the Serializable interface. You will also need a toString method, and maybe others.

  2. Define a SortedList class that represents a sorted list of objects. Like the Runner class, it should be Serializable. Since it needs to compare the objects that it stores in order to keep them sorted, they will need to be Comparable. Your SortedList class should have at least the following public methods: Note that this is a simple version of the list ADTs we have been working with.

  3. Define a ProcessRace class with a main method that takes input and output filenames at the command line. It should assume that the input file is in the format specified above, and should produce an output file consisting of four SortedList objects -- the first holding the 7 and under runners, the second holding the 8-10 runners, the third holding the 11-14 runners, and the fourth holding the 15-17 runners. Of course, the objects in these lists will be sorted (by time).

  4. Define a ReadTimes class with a main method that takes the name of a file such as that produced by ProcessRace at the command line and prints the sorted, age-grouped results to the command line.

The Runner class is very small, and the SortedList class should be familiar. Most of the work for this program will be in the ProcessRace class. It will need to read and parse the input file, create a SortedList of Runner objects for each age group, and use an ObjectOutputStream to write those lists to a file. ReadTimes is very simple; it just opens an ObjectInputStream to the file and reads and prints the SortedList objects.

Example

If the input data is in file runnerIn.dat and you want to put the binary data into file runnerOut.dat, a test run of your program might look like this:
$ java ProcessRace runnerIn.dat runnerOut.dat
$ java ReadTimes runnerOut.dat

 7 and under 
-------------
26.2  7  David Jones
33.2  6  Michael Watt

 8-10 
-------------
29.3  10  Jane Doe
29.5  10  John Doe

 11-14
-------------

p 15-17
-------------
20.0 17 Mark White
22.3 17 Susan Brown
25.8 15 Mary Ann Smith
Note that running ProcessRace produces the binary file but does not write anything to the standard output. The ReadTimes class then takes that binary file and reads and displays its contents.

As always, be sure to document your code.