THINK FIRST·CODE LATER

← All labs

Technical-debt register: what to repay first?

Problem

Plan technical-debt repayment for the next Sprint.

Input: first line capacityHours. Then items id principalHours interestHoursPerSprint risk until the end of input, where risk is LOW, MEDIUM or HIGH.

For each item compute the payback period principal / interest (in Sprints; if interest is 0, payback is infinite → print never). Order the items for repayment:

  1. all HIGH-risk items first,
  2. then by payback ascending (shorter first; never last),
  3. then by id alphabetically.

Go through the ordered list and select each item whose principal still fits in the remaining capacity (skip the ones that do not fit; smaller later items may still fit). Print the ordered list:

1. id: principal P h, interest I h/sprint, payback X sprints, risk R -> SELECTED|DEFERRED

(payback with one decimal or never), then Selected: h/capacity hours and Interest saved per sprint: s h (sum of interest of selected items).

Input:

16
matching-refactor 12 3 MEDIUM
notif-switch 6 4 LOW
no-tests-auth 10 1 HIGH
old-logging 2 0 LOW

Output:

1. no-tests-auth: principal 10 h, interest 1 h/sprint, payback 10.0 sprints, risk HIGH -> SELECTED
2. notif-switch: principal 6 h, interest 4 h/sprint, payback 1.5 sprints, risk LOW -> SELECTED
3. matching-refactor: principal 12 h, interest 3 h/sprint, payback 4.0 sprints, risk MEDIUM -> DEFERRED
4. old-logging: principal 2 h, interest 0 h/sprint, payback never, risk LOW -> DEFERRED
Selected: 16/16 hours
Interest saved per sprint: 5 h

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.

s13-4-data-1.txt

16
matching-refactor 12 3 MEDIUM
notif-switch 6 4 LOW
no-tests-auth 10 1 HIGH
old-logging 2 0 LOW
What your program must print for s13-4-data-1.txt
1. no-tests-auth: principal 10 h, interest 1 h/sprint, payback 10.0 sprints, risk HIGH -> SELECTED
2. notif-switch: principal 6 h, interest 4 h/sprint, payback 1.5 sprints, risk LOW -> SELECTED
3. matching-refactor: principal 12 h, interest 3 h/sprint, payback 4.0 sprints, risk MEDIUM -> DEFERRED
4. old-logging: principal 2 h, interest 0 h/sprint, payback never, risk LOW -> DEFERRED
Selected: 16/16 hours
Interest saved per sprint: 5 h

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

Windows PowerShell does not understand <:

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