Design and refactor a DeliveryFee calculator for a local courier service.
The fee rules are:
0 or less is invalid;1 through 10 km have a base fee of 50;11 through 50 km have a base fee of 100;50 km have a base fee of 160;40; and20.Implement String quote(int distanceKm, boolean express, boolean member). It returns "INVALID_DISTANCE" for an invalid distance. Otherwise, it returns "FEE: <amount>".
The legacy starter turns the distance into several boolean flags, later converts those flags back into a fee, and nests every combination of express and membership. It also gets the two tier boundaries wrong.
Refactor the method into a calculation that reads in the same order as the requirements.
Input:
Output:
Explanation: Both upper bounds are inclusive. Express and membership then adjust the chosen base fee independently.
Input:
Output:
Explanation: Once invalid input is handled, every valid quote is just a base fee followed by zero, one, or two adjustments.
-10^6 <= distanceKm <= 10^6100 calls will be made to quote.The starter compiles, but the extra flags and nested combinations obscure two off-by-one errors.
Full marks when quote uses an early invalid-distance return, one clear distance-tier decision and two direct adjustments. Lose points for classification flags, encoded keys, lookup matrices, scoring systems or deeply nested combinations.
Full marks when 10 km uses the 50 fee, 50 km uses the 100 fee and only larger distances use 160. Lose points for off-by-one boundaries or for applying member and express adjustments inconsistently.
Full marks for one stateless class with named fee constants or equally clear literals. Lose points for helper classes, mutable quote state, unnecessary configuration or printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new DeliveryFee() | null |
| quote(10, false, false) | "FEE: 50" |
| quote(50, true, true) | "FEE: 120" |
The two inclusive tier boundaries are where the legacy flag-based classification goes wrong.
Run checks these cases. Submit also runs a larger hidden set.

