Problem statement
Implement the nightly job of a library loan system that recalculates every overdue loan's fine and reports how many records it changed.
Requirements
FineRecalculationJob
Implement the recalculateFines method. Each run works on the stored loans as follows:
- For every loan whose dueDate is before today, set fineCents to the number of days the loan is overdue multiplied by 50. Days overdue are counted from dueDate to today: a loan due yesterday is 1 day overdue and gets 50, a loan due three days ago gets 150, a loan due ten days ago gets 500, and the count keeps growing across month boundaries
- The fine is always computed fresh from dueDate and today alone, never by adding to the stored value: a stored fine that no longer matches the computed value is overwritten, whether it is too low or too high
- A loan whose dueDate is today or later is never touched: its fineCents keeps whatever value it holds, zero or not
- Every overdue loan is updated in the same run, including loans that share the same dueDate
- The job only rewrites fineCents: it never adds or removes loans and never changes borrower or dueDate
- Because the fine depends only on dueDate and the current date, running the job a second time on the same day changes nothing: every value stays as it is and the run reports 0 changed records
- After each run, the job logs at INFO level exactly one line: "Fine recalculation changed " followed by the changed count, followed by " records", for example "Fine recalculation changed 2 records". The changed count is the number of loans whose stored fineCents actually changed in that run: loans that already hold the correct fine do not count, while every real change counts, whether the value went up or down. The line is also logged when nothing changed, as "Fine recalculation changed 0 records", for example when the store is empty or when no loan is overdue
The job must run automatically on the cron schedule given by the fines.recalc-cron property; the production default in application.properties is "0 0 2 * * *", which is 02:00 every night. The schedule must be read from that property: when the property value changes, the job follows the new schedule without any code change.
SchedulingConfig
Out of the box this application never executes any periodic work. Switch on the execution of scheduled jobs here; without this, no schedule ever fires.
Provided loans endpoint
GET /loans is provided and complete: it returns every stored loan with its id, borrower, dueDate, and fineCents, and reflects whatever fines the job has recalculated. Three loans are seeded at startup for manual exploration.
Sample Requests & Responses
Expand to view details on sample requests and responses.
GET /loans
Response (200 OK), with the seeded loans and before any job run:
[
{
"id": 1,
"borrower": "Alice Johnson",
"dueDate": "2026-08-02",
"fineCents": 0
},
{
"id": 2,
"borrower": "Bruno Marchetti",
"dueDate": "2026-09-15",
"fineCents": 0
},
{
"id": 3,
"borrower": "Chen Wei",
"dueDate": "2026-07-28",
"fineCents": 350
}
]
Log line written by a run that updated two loans:
Fine recalculation changed 2 records
Log line written by a second run on the same day:
Fine recalculation changed 0 records
