Assignment 3: Triathalon Manager
University of Toronto, St. George Campus
Due at the beginning of your tutorial Thursday August 2nd.
Worth 8% of the Course Grade
A triathalon is a sport that consists of three separate events, which always take place in the following order: swimming, bicycling, and running. Each of these events is completed in succession, with a continuous (cumulative) running time. The business of managing triathalon races is often computerized, especially considering the large number of participants who often compete in triathalons. Quite often triathalons are organized into a number of categories, such as youth, women, and men.
Our model of a triathalon starts with the user specifying how many categories are in the triathalon. Next, the user should register the athletes who will compete in each category. When an athlete is registered, s/he is assigned a unique athlete number. On occasion, an athlete might withdraw from the competition; in this case, his/her registration information is deleted from the appropriate category.
We are also interested in modelling the collection of timing information during the competition. During the race, the running time for each competitor is entered as they complete each event. In recent triathalons, each competitor is given a computer chip to carry during the race, that contains their assigned athlete number. As a competitor passes a checkpoint (the finish line for each of the three events), the chip records the current running time. In our model, timing information is entered into the program as each athlete in a category completes an event.
After the race is officially over, the results of the competition are printed. The overall results can be displayed, a summary for one category in the race, or a summary for an individual athlete in the race.
You have been provided with four files for this assignment: Assignment3.java, Triathalon.java, Category.java, and Athlete.java. Your task is to complete most of the Triathalon and Category classes, and parts of the Athlete class. These files contain comments that indicate where you need to add code.
Assignment3 class
This class contains the interface of the program. It has a main method where execution of the program begins. It displays a menu on the screen, and then continuously accepts commands from the user until the user enters the word "quit." This class contains a variable named triathalon, which is a reference to the Triathalon object. All Category objects and Athlete objects in the triathalon can be accessed through this object reference. The ONLY modification that you are allowed to make to this file is to change it so that it reads and writes from a file, rather than using standard input and output.
Triathalon class
This class contains the name of the triathalon and an array of references to each Category object that has been added so far. The categoryCount stores the count of how many categories have been added to the array so far. It is guaranteed that each category in the array of categories will have a different category name.
Category class
This class contains the name of the category and a Vector that stores references to each Athlete that has been added to this category so far.
The Category class also has variables that are used to generate the unique athlete numbers. The last digit of the athlete number for athletes in the first category that is added will end with "0". The next category that is added will have athlete numbers that end with "1", and so on for each category. The other digits in the athlete number are generated by counting each athlete registered in a category, starting at "1". The following example explains this:
Suppose we added a category for women and then a category for men. The athlete numbers of all women will end with "0", while the athlete numbers of all men will end with "1". If we add an athlete named Joe to the men category, he will be assigned the athlete number "11". If we add an athlete named Fred to the men category, he will be assigned the athlete number "21".Athlete class
This class stores all the information that is needed for a single athlete. It stores the athlete's name, athlete number, and the finish times for each of this athlete's events. The finish times are stored in an array that holds three integers (swim time, bike time, and run time). If an element in the array contains a value of zero, you can assume this means that this event time has not yet been entered for this athlete. Event times entered for athletes in a given category will be cumulative for each event. In addition, earliest times are entered first (i.e., in the order athletes pass the various checkpoints).
Download all four java files from the course web site. You will need to spend time -- perhaps quite a lot of time -- trying to understand how the code that is given to you works. Read through the code provided. Some of the techniques used in other classes may be required in the code that you need to write.
A sample transcript of the program has been provided on the course web site. Your program should produce similar output when it runs, using input1.txt as input. It is important to understand the relationship between the various objects in the program. The object space portion of the memory model diagram that shows the state of all objects that exist at the end of running the provided transcript is provided on the course web site. [Note that to simplify the memory model diagram, String objects are not drawn in their own object boxes, and binary numbers have not been used for the addresses.]
The comments in the java files provided indicate which parts of the program you'll need to modify. The comments also provide you with a description of what you will need to do.
The first thing you should do is fill in all missing method prototypes and add return statements (for all methods having a return type other than void) so that you can get the program to compile. If a method returns a value, temporarily add a return statement that returns something of the appropriate type (e.g., if the method returns an int, add a "return 0" statement for now, and if the method returns an object type, add a "return null" statement for now). To determine the prototype of a method, find the place where the method was called, and examine the type of its parameter(s) and determine the type of its return value (if any). The method comments that are provided will also prove helpful.
It makes the most sense to implement the code in the order in which the user must select the menu options to run the program. Start with the code related to initializing the triathalon, followed by the code for entering a category, then registering/deleting athletes, then adding event times, and finally the methods to display the reports. You may find it helpful to implement the toString methods of each class, to help with the debugging process. Temporarily add statements to call these toString methods if you are ever uncertain of the contents of an object in your program.
For this assignment, you are required to submit the output files that result when using the provided input1.txt and input2.txt files as input. You must provide a 3rd test file called input3.txt that tests the error messages that are printed by the Assignment3.java class. Use a highlighter or underline each error message printed. This test file should also demonstrate one limitation of your program - annotate your output (write comments on it by hand) to explain what your test shows.
Note that since the program is not meant handle input errors related to entering the wrong type of data (e.g., user inputs a String when program is expecting an integer), you do not need to show any tests of this sort.
For this assignment, you must type in the missing code and comments in the three class files that have been given to you, and then submit a printout of each of these class files. Do not submit a printout of the Assignment3.java file, as you will only be modifying its file I/O.
You must also submit your code (all four java files) on a 3.5" floppy diskette. You must label your diskette with your name and student number.
You must test your program using the input1.txt and input2.txt files that have been given to you. Your Assignment3 class should read the input from these files and automatically write the output to files called output1.txt and output2.txt, respectively. Submit a printout of the output1.txt and output2.txt files. You do not need to annotate these output files.
You must also create one more test input file, called input3.txt, as described in the previous section. Store the output for input3.txt in output3.txt. You must submit both the input and output files for this test. Don't forget to highlight and annotate your output3.txt file.
The pages in your assignment should be stapled together, in the following order: Triathalon, Category, Athlete, output1.txt, output2.txt, input3.txt, and output3.txt. Put your printouts and your floppy diskette into an 8.5x11" unsealed envelope; fasten the completed cover page to the outside of the envelope, and hand the envelope in to your TA at the beginning of your tutorial.
Be sure to start this assignment early!!! It will take a lot of time to understand the code that has been provided. Reading the transcript and studying the provided object diagram will also be very helpful.