Skip to content
ExamSpine

Lesson 5.19 · Write it

Sports day report

A whole programPython or Java8 tests, 5 of them hidden

On a phone? Put the lines in order instead

Write a program that reads the results of a sports day, one record per line, and prints a short report.

  1. The first line is the name of one house, typed in any mix of capital and small letters, for example red.
  2. The second line is the number of records, a whole number from 1 to 50.
  3. Each record is one line: a name, a house and a score, separated by commas with no spaces around them. For example: Mei Lin,Red,88. A name can have spaces in it but no commas. A house is one word. A score is a whole number from 0 to 100.
  4. Print House total: and the scores of every record whose house is the house from the first line added up. Capital letters do not matter when matching: red, Red and RED are the same house. If no record matches, the total is 0.
  5. Print Average: and the average of all the scores, as a whole number (drop the fraction).
  6. Print Above average: and the names of everyone whose score is above that whole-number average, in the order they were read, with a comma and a space between names. If nobody is above it, print Above average: none.
  7. Print Top: , the name with the highest score, with , and that score. If two or more share the highest score, give the one read first.

For the first example below, the program prints:

House total: 160
Average: 63
Above average: Ana, Mei Lin
Top: Mei Lin with 88

Your program is run several times. Only what it prints is checked.

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 8 times: the 3 examples below, and 5 hidden ones that check the rules above. Only what it prints is checked.

  • the example: the house typed in small letters, two names above average (rules 4, 5, 6, 7)

    You type

    1. typed: red
    2. typed: 4
    3. typed: Ana,Red,72
    4. typed: Leo,Blue,55
    5. typed: Mei Lin,Red,88
    6. typed: Sam,Green,40

    It prints

    House total: 160
    Average: 63
    Above average: Ana, Mei Lin
    Top: Mei Lin with 88
  • two records share the top score, and the one read first is given (rule 7)

    You type

    1. typed: Blue
    2. typed: 3
    3. typed: Kofi,Blue,90
    4. typed: Ines,Green,90
    5. typed: Tom,Blue,30

    It prints

    House total: 120
    Average: 70
    Above average: Kofi, Ines
    Top: Kofi with 90
  • every score equals the average, so nobody is above it (rule 6)

    You type

    1. typed: GREEN
    2. typed: 2
    3. typed: Ravi,Green,50
    4. typed: Zoe,Red,50

    It prints

    House total: 50
    Average: 50
    Above average: none
    Top: Ravi with 50
solution.pySolution.java