csH-JavaX-2021
Share
Explore

# triathlon timestriathlon times

## instructions

you should already have completed a tutorial using modulo % to calculate a remainder, 7%4 is 3
remember that integer division discards the remainder (always rounds down, 7/4 is 1)

the code has 4 arrays storing the names and swim, run and bike times for triathlon competitors.
the times are given in whole seconds for all three events
add code to calculate and display the total time for each competitor in hours minutes and seconds as shown:

Chenai 1:45:52
You will need to calculate a total time (in seconds) for each competitor. It would be useful to use a separate variable for this value.
Use the time results for one of the competitors to decide how you can calculate each of the values for the hours, minutes and seconds. You may want to store each of these values in a variable.
You will need to use both integer division and modulo operators.

### challenge: qualifiers

Any competitor with a total time of less than 1:50:00 will qualify for the next world championships, a Q should appear beside their name.
This will require an `IF` construct nested within the loop.
output
Chenai Q 1:46:0
Balraj 1:51:55
..
Romana Q 1:47:56
Ines 1:55:9
design
if total time is below 1:50:00
display Q
end if

### challenge: qualifier count

Calculate and display the number of world championship qualifiers.
output
Chenai Q 1:46:0
Balraj 1:51:55
..
Zayn 1:51:33
Vikki Q 1:49:28
Warwick 2:1:18
..
Shanaya 1:55:1
Collette Q 1:49:11
Shannon 2:0:46
Kacy 1:50:5
Bessie 1:54:3
Mercy Q 1:49:25
Romana Q 1:47:56
Ines 1:55:9
Number of qualifiers is: 5
design and code
// initialise qCount
int qCount = 0;

// update qCount
qCount = qCount + 1;

// display qCount
SYstem.out.println("Number of qualifiers is: " + qCount);

### challenge: identify and count elite competitors

An elite competitor is one who has a swim time less than 1500 sec, a run time less than 1950 and a bike time less than 3500. These competitors should have an E beside their name and the number of elite athletes should be displayed at the end.
// initialise eCount
// update eCount
// display eCount

### challenge: slowest swim

how long did the slowest swim take?
// initialise
int maxSwim = 0;

// update
if (swimTimes[i] > maxSwim) {
maxSwim = swimTimes[i];
}

// report
System.out.println("Longest swim time is " + maxSwim);

### challenges: first and last

Name of the swimmer who took longest
Name of the fastest swimmer and the time
Overall fastest athlete and the total time in HH:MM:SS

Using position of highest value and parallel array
// initialise
int maxSwim = 0;
int maxSwimPos = 0;

// start loop

// update value and position
if (swimTimes[i] > maxSwim) {
maxSwim = swimTimes[i];
maxSwimPos = i;
}

// end loop

// report
System.out.println("Longest swim time is " + maxSwim);
System.out.println("Longest swim name is " + competitor[maxSwimPos]);

Using 1st value position of highest value and parallel array
// initialise
int minSwim = swimTimes[0];
int minSwimPos = 0;

for (int i=1; i<swimTimes.length; i++) {

// update value and position
if (swimTimes[i] < maxSwim) {
minSwim = swimTimes[i];
minSwimPos = i;
}

}

// report
System.out.println("Fastest swim time is " + minSwim);
System.out.println("Fastest swim name is " + competitor[minSwimPos]);