THINK FIRST·CODE LATER

← All labs

Risk register: exposure and priorities

Problem

Turn a list of risks into a prioritized register.

Input: lines id probability impactDays category until the end of input; probability is between 0 and 1, category is one word (AI, PEOPLE, EXTERNAL, TECH…).

Compute exposure = probability × impact. Print the risks sorted by exposure descending (on a tie, by id alphabetically), one per line:

id: P=0.40 I=20 exposure=8.00 [LEVEL] category

with LEVEL HIGH if exposure ≥ 5, MEDIUM if ≥ 2, else LOW. Then:

Total exposure: x.xx days
Suggested buffer: y days
By category: AI=.., EXTERNAL=.., ...

The buffer is the total exposure rounded up to a whole number of days. "By category" lists the sum of exposure per category with two decimals, categories in alphabetical order.

Input:

R1 0.4 20 AI
R2 0.5 10 PEOPLE
R3 0.2 25 EXTERNAL
R4 0.3 8 AI

Output:

R1: P=0.40 I=20 exposure=8.00 [HIGH] AI
R2: P=0.50 I=10 exposure=5.00 [HIGH] PEOPLE
R3: P=0.20 I=25 exposure=5.00 [HIGH] EXTERNAL
R4: P=0.30 I=8 exposure=2.40 [MEDIUM] AI
Total exposure: 20.40 days
Suggested buffer: 21 days
By category: AI=10.40, EXTERNAL=5.00, PEOPLE=5.00

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.

s5-4-data-1.txt

R1 0.4 20 AI
R2 0.5 10 PEOPLE
R3 0.2 25 EXTERNAL
R4 0.3 8 AI
What your program must print for s5-4-data-1.txt
R1: P=0.40 I=20 exposure=8.00 [HIGH] AI
R2: P=0.50 I=10 exposure=5.00 [HIGH] PEOPLE
R3: P=0.20 I=25 exposure=5.00 [HIGH] EXTERNAL
R4: P=0.30 I=8 exposure=2.40 [MEDIUM] AI
Total exposure: 20.40 days
Suggested buffer: 21 days
By category: AI=10.40, EXTERNAL=5.00, PEOPLE=5.00

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

Windows PowerShell does not understand <:

Get-Content s5-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.