University of Toronto Department of Computer Science
CSC108H, Summer 1998
Assignment 3: Triathlon Information
Due: at the
beginning of your tutorial Wednesday, Jul 15.
A triathlon is a sport involving three separate events: swimming, bicycling
and running, run in succession with continuous running time. The business of
running triathlons has been computerized. The registration process involves
human data entry. Our model begins when a person registers. At this point a
competitor's category is determined and a unique triathlete number is
assigned. We are also interested in modeling, collecting timing information
during the competition. During the race, the running time for each competitor
is entered as they complete each event. Timing information and the order of
finishers in each event is updated as times are entered. After the race is
officially over, the results are printed.
In recent triathlon's, each competitor is given a computer chip to carry
during the race, that contains an assigned triathlete number. As a competitor
passes a checkpoint, the chip reports this number to a checkpoint sensor that
sends the sensor's event, assigned triathlete number, and the current running
time to a central computer which calculates the individual's event time.
There are checkpoints at the end of the swim, the bike and the run which is
also the finish line. Sometimes triathlons end with the swim. In particular,
you cannot assume that swim times are entered at the computer in the order
that they should finish the swim.
The program begins by reading in ``MaxTriathlonSize'' literally followed by a
number which will be the maximum number of competitors allowed.
Your program must contain at least five classes.
- a class containing the command line interface for the triathlon
containing only a main method, which processes the commands listed below.
The main method creates a single local object of the next class.
- a class representing all competitor categories: specifically
representing two categories (2 instance variables of the next class) - men
and women - assigning a right digit code of ``0'' for men and ``1'' for
women. E.g. triathlete 101 is a woman and 210 is a
man. This makes it easy for the main method to retrieve a category (object).
- a class representing a single category of competitors allowing
registration and assigning a triathlete number ``counter + code'' concatenated
beginning with counter = 1. The list of registered triathlete's in a category
can be searched by number (an instance array of next class). Ordering of
competitor's times are included for each event as well as the overall time (an
instance array of the event order class).
- a triathlete class representing a triathlete's name, assigned number,
event and final times.
- An event order class contains alternate orderings of the registration
list of a list of triathletes. You will need one for each of swim, bike,
run and final times (an instance array of the triathlete class).
Write a Java program that reads the commands and associated data listed below
and processes the data appropriately.
- MaxTriathlonSize
- followed by a positive integer on the next line.
- the first command, read once only, sets the maximum number of
competitors in each category.
- Register
- followed by name on the next line
- followed by category on the next line
- Category assigns a number using a counter concatenated with the
category code as described earlier. This number is reported.
- WithdrawTriathlete
- followed by competitor's number only.
- retrieves category, finds triathlete, deletes this competitor from
their category.
- AddEventTime
- followed by competitor's number.
- followed by an event, one of swim, bike, or run.
- followed by current time in seconds.
- retrieve the appropriate category, find the triathlete, add the
incremental event time, insert triathlete to appropriate place in the
event ordering, and calculates the final time if you are entering the
current time at the end of the run which is the finish line.
- ReportEventCategoryTime
- followed by category name
- followed by event name
- retrieves category by name, reports times for all competitors in this
category ordered by event time.
- ReportCategoryTime
- followed by category name
- reports times for all competitors ordered by final time.
- ReportEventTime
- followed by event name
- reports times for all competitors in all categories ordered by event
time.
- ReportTimeAll
- no other input required.
- reports times for all competitors in all category ordered by final
time.
- ReportRegistered
- no other input required.
- lists all competitors (name, number) in all categories that are
Registered.
- Stop - terminates the program.
For each competitor, event times are entered in the order of the events; swim,
bike, run. It is possible that a competitor may have a faster time in some
events that other competitors yet have their times entered later simply
because another competitor could be faster in an earlier event. If a
competitor doesn't finish an event then you can't insert them into an event
ordering. Current time is entered in seconds, the output event and final
times should be of the form:
<hours>:<minutes>:<seconds>.
If input is invalid then you should handle it in a reasonable way.
You are required to do minimal error checking and handling only for
this assignment. However, you may earn a maximum of two bonus marks
for good error checking and handling.
(The maximum grade for the assignment is 10. The bonus marks may be
used to offset marks you lose for other reasons.)
Required test input file
Sample output on this input file
- This program will be larger and more complex than your first two.
Start this assignment early.
- Look at the Roll_Call example on pp. 223-224 of your textbook. The
relationship between the classes there and the use of an array of
objects of class Member is similar to what you must implement for this
assignment. The Member class is close to the single category class
described above.
Also look at Assignment 3 from the Spring term.
- Think about the structure of your program carefully before you start
writing it. For example, what data should each class contain and what
services should it provide to its clients? Start by drawing an object
diagram of the relationships between the classes. If you get the
structure right, the program will be much easier to write.
- Get the essential parts working first before you try to complete
the whole program. For example, be sure that your triathlete class
works correctly by testing it thoroughly on its own before you
include it in your full program.
- Start small: Begin with a simplified version of the assignment. For
example, you might first write a simplified version of the program in
which the triathlete class contains only the name, number and event
time of each triathlete and implement only the MaxTriathlonSize,
Register, and the ReportRegistered command. After this simplified
program is working, add the other classes and commands. Finally, add
error detection and handling. (See the section on Bonus Marks above.)
Note that, if you follow this strategy and you don't complete all of
the assignment, you will still have something that works to hand in.
- If you do attempt to detect errors and handle them appropriately,
you might find it useful to read pages 488 to 492 or your textbook
first. This section discusses Java's exception handling
facilities.
- Include results for valid as well as invalid input that your
program processes correctly. Also include runs which demonstrate
restrictions on the use of your program. For example, you should
illustrate its inability to handle invalid input, if applicable.
This should show that you understand what invalid data might cause
your program problems, even if you do not detect and handle them.
- Label and attach each input file to its output files.
Please use the ``Print Java Assignment'' program.
Wed Jun 24 15:40:04 EDT 1998
Craig MacDonald
Wed Jun 24 15:40:08 EDT 1998