Refactor the Validator
Challenge on lesson: Checkpoint: Professional Code
CHALLENGE
Difficulty: intermediate+25 XP
static String validateOrder(String id, int cents, String coupon)
returns one of "OK", "BAD_ID", "BAD_AMOUNT", "BAD_COUPON" โ
first failure wins. Rules:
- id: non-null, 3..20 chars โ else BAD_ID
- cents: 1..1_000_000 โ else BAD_AMOUNT
- coupon: null/empty OK; otherwise must match [A-Z0-9]{4,10} โ
else BAD_COUPON
Implement it CLEANLY: extract static boolean isValidId(String id),
static boolean isValidAmount(int cents), and
static boolean isValidCoupon(String coupon) โ validateOrder calls the
three helpers, no duplicated rule logic, guard-style.
Press Submit to check your solution.
Back to lesson: Checkpoint: Professional Code