THINK FIRST·CODE LATER

← All labs

Privacy-safe statistics for instructors

Problem

Instructors may see Buddy usage statistics per group (course section), but a statistic for a small group can reveal individuals. Implement a report with a minimum group size.

Input: first line minSize. Then lines section studentPseudonym questions (weekly number of Buddy questions of one student), until the end of input. A student appears at most once per section.

For each section, in order of first appearance, print either

section: students n, total t, average a.a, max m

or, if the section has fewer than minSize students,

section: hidden (fewer than minSize students)

Then print an overall line for all students: ALL: students n, total t, average a.a — but also apply a complementary-disclosure check: if exactly one section is hidden and the overall line is shown, a reader could subtract the visible sections from the total to recover the hidden section. In that case print ALL: hidden (would reveal a small section) instead. (If the overall number of students is below minSize, print ALL: hidden (fewer than minSize students).)

Input:

5
W01 s1 3
W01 s2 5
W01 s3 0
W01 s4 2
W01 s5 10
W02 s6 7
W02 s7 1

Output:

W01: students 5, total 20, average 4.0, max 10
W02: hidden (fewer than 5 students)
ALL: hidden (would reveal a small section)

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.

s11-4-data-1.txt

5
W01 s1 3
W01 s2 5
W01 s3 0
W01 s4 2
W01 s5 10
W02 s6 7
W02 s7 1
What your program must print for s11-4-data-1.txt
W01: students 5, total 20, average 4.0, max 10
W02: hidden (fewer than 5 students)
ALL: hidden (would reveal a small section)

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 < s11-4-data-1.txt

Windows PowerShell does not understand <:

Get-Content s11-4-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.