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
Press Submit to check your solution.
Back to lesson: Practice: Clean Code Lab