THINK FIRST·CODE LATER

← All labs

Club members: set algebra

Problem

Write ClubSets. Read the members of the chess club (n, then n names) and of the robotics club (m, then m names) into two TreeSet<String>. Without modifying the two original sets, print the union, the intersection, the members only in chess, the members in exactly one club, whether every robotics member plays chess, and whether the clubs share nobody.

For the input

4 Lina Omar Mei Ana
3 Mei Bo Lina

the program prints

Chess: [Ana, Lina, Mei, Omar]
Robotics: [Bo, Lina, Mei]
In at least one club (5): [Ana, Bo, Lina, Mei, Omar]
In both clubs: [Lina, Mei]
Only chess: [Ana, Omar]
In exactly one club: [Ana, Bo, Omar]
Every robotics member plays chess: false
No shared members: false

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.

d5-5-data-1.txt

4 Lina Omar Mei Ana
3 Mei Bo Lina
What your program must print for d5-5-data-1.txt
Chess: [Ana, Lina, Mei, Omar]
Robotics: [Bo, Lina, Mei]
In at least one club (5): [Ana, Bo, Lina, Mei, Omar]
In both clubs: [Lina, Mei]
Only chess: [Ana, Omar]
In exactly one club: [Ana, Bo, Omar]
Every robotics member plays chess: false
No shared members: false

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 < d5-5-data-1.txt

Windows PowerShell does not understand <:

Get-Content d5-5-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.