Tiered cost plus an optional surcharge.
A base cost determined by a numeric tier, plus an additional charge if a boolean flag is true.
Many real-world pricing problems combine two patterns: a tiered base cost based on a numeric input (weight, distance, age) and a boolean surcharge added if a flag is set (fragile, express, weekend).
The clean structure: compute the base via an if/else if ladder; then add the surcharge with a single if; return the total.
On the AP exam, this combined pattern appears in pricing-style FRQs and stat-based MCQs.
Tier first; surcharge second; sum.
Two stages, one return.
The template
public double calculateCost(double weight, boolean fragile) {
double base;
if (weight > 50) base = 100;
else if (weight > 20) base = 60;
else if (weight > 5) base = 20;
else base = 5;
double surcharge = fragile ? 25 : 0;
return base + surcharge;
}
Ternary for the surcharge
fragile ? 25 : 0 is shorthand for an if/else that picks 25 or 0. Equivalent to:
double surcharge;
if (fragile) surcharge = 25;
else surcharge = 0;
Order independence
The surcharge can come before or after the tiered calculation — they're independent. Compute each cleanly, then combine.
Why keep them separate?
Mixing the surcharge into each tier branch means writing + 25 in four places (one per tier). Computing it once and adding once is cleaner and avoids duplication bugs.
Tier + surcharge vocabulary.
Used in pricing FRQs.
- Base cost — primary charge from the tier.
- Surcharge — additional charge for a feature.
- Tier — range bucket determining base cost.
- Boolean flag — true/false input determining surcharge.
- Ternary —
cond ? a : bexpression. - Total — base + surcharge.
How tiered + boolean problems are tested.
Combining the two correctly is the trap.
- Tier ladder ordered high to low. Standard rule.
- Surcharge independent. Add after base is computed.
- Boolean simply tested.
if (flag), notif (flag == true). - Return type matches both. Usually
doublefor money.
MCQ patterns: trace the total for several (weight, flag) combinations; identify which inputs produce the same total.
Calculate shipping with surcharge.
Combine tier and flag across multiple inputs.
Setup. Using calculateCost above. Compute cost for several inputs.
- weight = 25, fragile = false: base = 60, surcharge = 0 → 60.
- weight = 25, fragile = true: base = 60, surcharge = 25 → 85.
- weight = 3, fragile = true: base = 5, surcharge = 25 → 30.
- weight = 75, fragile = false: base = 100, surcharge = 0 → 100.
- weight = 75, fragile = true: base = 100, surcharge = 25 → 125.
Boundary check. weight = 20 (boundary): 20 > 50 false; 20 > 20 false; 20 > 5 true → base = 20. Using strict > matters — 20 falls into the third tier, not the second.
Why this matters. The tier and surcharge contribute independently to the total. Trace each separately, then sum.
Tier + surcharge pitfalls.
Most mix the two stages or test the boolean awkwardly.
- Putting the surcharge inside the tier ladder. Each branch ends up adding the surcharge separately — easy to miss one branch.
- Testing
flag == true. Redundant — just writeif (flag). - Forgetting to add the surcharge to base. Returns only one of the two contributions.
- Wrong tier order. Standard ladder mistake — high to low.
- Returning inside the ladder before adding the surcharge. The early return skips the rest of the method.
- Mixing up boundary operators.
>vs>=shifts boundary values into the wrong tier.
Tier + surcharge structure.
Two stages; one total.
Tiered + Boolean Reference
AP Quick Reference| Stage | Structure | Output |
|---|---|---|
| Tier ladder | if/else if/else | base cost |
| Boolean check | if (flag) or ternary | surcharge |
| Combine | base + surcharge | total |
| Return | Single value | double or int |
How to master tiered + boolean problems.
Separate the stages; compute each cleanly; combine at the end.
Use the three practice tools below this lesson in order:
- MCQ Practice — for each input combination, compute base and surcharge independently, then sum.
- Java Lab — write calculateCost variants with different tiers and flags. Test all four combinations of tier × flag boundary values.
- FRQ Practice — outline base and surcharge as separate variables; combine at the return.
If you can split any pricing problem into "tier first, surcharge second, sum at the end", this hybrid pattern becomes a confident, high-credit FRQ response.
Practice — attempt these now.
AP-style assessments aligned to this lesson. Time them.
AP CSA Unit 09 Topic 10 Tiered Cost with a Boolean Surcharge FRQ Practice
AP-style topic practice assessment