THINK FIRST·CODE LATER

← All labs

Race results with Comparable

Problem

Write a class Runner implements Comparable<Runner> (name, club, time in seconds — the constructor parses "42:07"). compareTo orders faster runners first and, for equal times, by name.

RaceResults.main reads n and n lines name club mm:ss, sorts with Arrays.sort, and prints the ranking. Runners with the same time share a place (the next place is skipped, like 1, 2, 2, 4). The first three places get gold, silver, bronze:

1. Lina     WKU    38:12 gold
2. Mei      Kean   40:05 silver
2. Omar     WKU    40:05 silver
4. Ana      Kean   44:30
Gap first to last: 6 min 18 s

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l15-3-data-1.txt

4
Omar WKU 40:05
Lina WKU 38:12
Ana Kean 44:30
Mei Kean 40:05
What your program must print for l15-3-data-1.txt
1. Lina     WKU    38:12 gold
2. Mei      Kean   40:05 silver
2. Omar     WKU    40:05 silver
4. Ana      Kean   44:30
Gap first to last: 6 min 18 s

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l15-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content l15-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.