Practice ยท 2 of 3
Extract the Pricing Collaborator
static class GodCart (provided in the starter comments โ recreate
it fixed) computes totals, applies discounts, and formats receipts in
one method. Refactor by extraction:
- static class Pricing with static int total(List<Integer> centsList,
int discountPercent) โ sum minus percentage discount (integer math).
- static class GodCart now takes Pricing as a constructor dependency
(any object works โ you accept Object and call the static method,
or accept nothing; keep it simple: the cart delegates to
Pricing.total) and exposes String receipt(List<Integer> centsList,
int discountPercent) returning "TOTAL: $" + viewTotal(total) using
your Module-12 viewTotal from the previous challenge โ define it
again here.
The seam test: receipt(List.of(1000, 500), 10) โ total 1350 โ
"TOTAL: $13.50".
Difficulty: intermediate
Back to lesson: Practice: Architecture Lab