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.
- The first line is the name of one house, typed in any mix of capital and small letters, for example
red. - The second line is the number of records, a whole number from 1 to 50.
- 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. - 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,RedandREDare the same house. If no record matches, the total is 0. - Print
Average:and the average of all the scores, as a whole number (drop the fraction). - 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, printAbove average: none. - 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
- typed: red
- typed: 4
- typed: Ana,Red,72
- typed: Leo,Blue,55
- typed: Mei Lin,Red,88
- 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
- typed: Blue
- typed: 3
- typed: Kofi,Blue,90
- typed: Ines,Green,90
- 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
- typed: GREEN
- typed: 2
- typed: Ravi,Green,50
- typed: Zoe,Red,50
It prints
House total: 50 Average: 50 Above average: none Top: Ravi with 50