Skip to content
ExamSpine

Lesson 6.10 · Write it

Fastest lap

A whole programPython or Java9 tests, 7 of them hidden

On a phone? Put the lines in order instead

A running club saves lap times in laps.csv. Write a program that finds the fastest lap and the total time.

  1. The first line is a header, name,seconds. Every other line is one lap: the runner's name, a comma, then the lap time in whole seconds, such as Bo,58.
  2. Print Fastest: , the name of the runner with the smallest time, in , that time, and seconds, such as Fastest: Bo in 58 seconds.
  3. If two laps share the smallest time, the one nearer the top of the file is the fastest.
  4. Then print Total: , the sum of all the times, and seconds.
  5. There is at least one lap. Times are whole numbers from 1 to 999, written with digits only, and no field has spaces around it. The last line may or may not end with a line end.

Your program is run several times, each time in a folder that holds only the files shown for that run.

Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.

Examples

Your program is run 9 times: the 2 examples below, and 7 hidden ones that check the rules above. Only what it prints is checked. Each run starts in an empty folder that holds only the files shown for it.

  • three laps, the fastest in the middle (rules 2 and 4)

    You type

    Nothing

    It prints

    Fastest: Bo in 58 seconds
    Total: 183 seconds

    Files in its folder

    laps.csv
    name,seconds
    Ana,64
    Bo,58
    Cy,61
  • times with different numbers of digits: 9 is less than 10 (rules 2 and 5)

    You type

    Nothing

    It prints

    Fastest: Bo in 9 seconds
    Total: 31 seconds

    Files in its folder

    laps.csv
    name,seconds
    Ana,12
    Bo,9
    Cy,10
solution.pySolution.java

Report a problem with this page