THINK FIRST·CODE LATER

← All labs

Retention policy enforcer

Problem

Implement StudyBuddy's storage-limitation job, which runs every night.

Input:

TODAY day
POLICY
<lines: dataType retentionDays>
DATA
<lines: itemId dataType createdDay [HOLD]>

Days are integers (day numbers). An item must be deleted if today - createdDay >= retentionDays for its type — unless it is marked HOLD (a legal hold, e.g., an ongoing misconduct case), in which case it is kept and reported. An item whose type has no policy is flagged: itemId: NO POLICY (review) — data without a retention rule is a finding, not something to keep silently.

Output per item, in input order: itemId: KEEP (d days left), itemId: DELETE (expired d days ago) (d = today - createdDay - retentionDays; 0 means it expires today), itemId: KEEP (legal hold, expired) or itemId: KEEP (legal hold) depending on whether it would otherwise be expired, or itemId: NO POLICY (review).

At the end: Delete: x, Keep: y, Hold: h, No policy: z.

Input:

TODAY 200
POLICY
chat 90
post 180
log 30
DATA
c1 chat 100
c2 chat 150
p1 post 10
p2 post 30 HOLD
l1 log 170
x1 photo 50

Output:

c1: DELETE (expired 10 days ago)
c2: KEEP (40 days left)
p1: DELETE (expired 10 days ago)
p2: KEEP (legal hold)
l1: DELETE (expired 0 days ago)
x1: NO POLICY (review)
Delete: 3, Keep: 1, Hold: 1, No policy: 1

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

TODAY 200
POLICY
chat 90
post 180
log 30
DATA
c1 chat 100
c2 chat 150
p1 post 10
p2 post 30 HOLD
l1 log 170
x1 photo 50
What your program must print for s11-3-data-1.txt
c1: DELETE (expired 10 days ago)
c2: KEEP (40 days left)
p1: DELETE (expired 10 days ago)
p2: KEEP (legal hold)
l1: DELETE (expired 0 days ago)
x1: NO POLICY (review)
Delete: 3, Keep: 1, Hold: 1, No policy: 1

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

Windows PowerShell does not understand <:

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