Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

triathlon

Language/Type: Java file processing Scanner
Author: Jessica Miller (on 2010/12/28)

Write a static method named triathlon that accepts as its parameter a Scanner for an input file whose data represents triathlon race results for athletes. Your method should add up the swimming, biking, and running times for each athlete and report the total time for each athlete and their time difference from the winner's. The input consists of a series of tokens. Each athlete's data is represented by four tokens in the following order: athlete's first name, swimming time, biking time, and running time (all times are given in minutes). The data for an athlete may or may not span multiple lines, but you are guaranteed the athletes will come in the order they finished the race (the winner's data is first, the second place triathlete's data comes next, etc.).

Here is an example input file. Notice the spacing and that the order the athletes appear in the file are in the same order that they finished the race:

Meghan 12 40 23 Bryan 16
42 20 Lori 14 41 29 Jessica 18

    37 30 Toni 19   43
29 Tamara 17 42 34

For this input, you method should produce the output below. For example, Meghan swam for 12 minutes, biked for 40 minutes, and ran for 23 minutes so it took for Meghan 75 minutes to finish the race. Notice that for the athletes that did not win the race, in addition to reporting their total race time, the difference in their time from the winner's is also reported. For example, Bryan swam for 16 minutes, biked for 42 minutes, and ran for 20 minutes so it took Bryan 78 minutes to finish the race, which is 3 minutes longer than Meghan's winning time of 75 minutes.

Meghan: 75 min
Bryan: 78 min (+3 min)
Lori: 84 min (+9 min)
Jessica: 85 min (+10 min)
Toni: 91 min (+16 min)
Tamara: 93 min (+18 min)

You may assume that the file contains data for at least one athlete. You may also assume that the input is valid; that the input has four tokens per athlete, the first token for an athlete is a String and the following three are integers.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.