Skip to main content

Practice ยท 2 of 2

The service over either engine

Inside Solution, add public static class LedgerService: 1. Constructor takes an Engine and stores it (polymorphism by construction). 2. String get(String key) โ€” returns the value or the literal "MISSING" (the service shapes the engine's Optional into domain language). 3. void record(String key, String value) โ€” delegates to engine.put. 4. java.util.List<String> entries() โ€” engine.keys() mapped to key=value strings, in the engine's (sorted) order. 5. static String health(int count, int failures) โ€” returns "green" if failures == 0 and count > 0, "yellow" if failures == 0 and count == 0, "red" otherwise.

Difficulty: advanced

Back to lesson: Practice: Capstone build