Skip to main content

Practice · 2 of 3

A Total Built from Named Pieces

CHALLENGE
Difficulty: intermediate+25 XP

Money math belongs in small named pieces, not one formula. Implement four methods: - Subtotal(lines) — sum of Qty * Price - Discount(subtotal, pct) — subtotal * pct / 100 - Shipping(afterDiscount) — free (0) when afterDiscount >= 100, else 5m - Total(lines, pct) — subtotal - discount + Shipping(subtotal - discount) The shipping decision reads the **after-discount** amount — that ordering is the whole point. ``csharp public static class Solution { public static decimal Subtotal(System.Collections.Generic.IEnumerable<OrderLine> lines); public static decimal Discount(decimal subtotal, decimal pct); public static decimal Shipping(decimal afterDiscount); public static decimal Total(System.Collections.Generic.IEnumerable<OrderLine> lines, decimal pct); } ``

Back to lesson: Practice: Clean Code Practice: Guards, Totals, Reports