Skip to main content

Practice ยท 1 of 3

Guard Clauses & Honest Names

Refactor (re-implement) static int shipFee(int weightGrams, boolean vip, String country) โ€” behavior frozen by these tests, but the implementation must use GUARD CLAUSES (no else-nesting) and the local variables must carry meaningful names: - country not "VN" or "SG" โ†’ IllegalArgumentException - weight <= 0 โ†’ IllegalArgumentException - base fee: 400 cents; plus 200 if weight > 2000 - vip: 50% off the running total (integer division) The grader checks behavior AND structure: the method must not contain an else branch and must use a variable named feeCents.

Difficulty: intermediate

Back to lesson: Practice: Clean Code Lab