5013

Gilded Rose in the Warehouse

Extensibility
Medium
Pro
interface
implements
strategy-pattern
refactoring
golden-master

Gilded Rose in the Warehouse

Every night at 02:00, the warehouse's aging job runs one procedure over every bin: "Stock Aging".AdvanceDay, a nested-if monolith untouched since 2011. Fifteen years of markdown pricing, insurance audits and event promotions were built on exactly what it does — including one boundary quirk nobody dares to touch. Now purchasing has signed a fresh-cut flowers supplier, the monolith has no branch for flowers, and you refuse to add a fifth arm to that if-tree. Your job: refactor the monolith into an enum-plus-interface strategy, faithful to the legacy behavior to the last unit, then plug the new category into the seam you just built.

The rules the warehouse lives by

One call to AdvanceDay ages one bin by one day. D below means the Days-to-Expire value before the call; every category except Legendary Stock ends the call with days lowered by exactly 1.

  • Fresh Produce — quality falls by 1, or by 2 when D <= 1; quality never falls below 0.
  • Aging Cheese — quality rises by 1, or by 2 when D <= 1; quality never rises above 50.
  • Event Stock — quality rises by 1 when D >= 11, by 2 when 6 <= D <= 10, by 3 when D <= 5, capped at 50 — but when D <= 1 quality is written off to exactly 0 instead (no tier gain survives the write-off).
  • Legendary Stock — insured: quality and days both stay exactly as they are, whatever their values.
  • Cut Flowers (the new category) — quality falls by 2, or by 4 when D <= 1; quality never falls below 0; days fall by 1 like any perishable.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 21 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade