Design a Pizza Price Calculator with Separate Pricing Components
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
Design an object-oriented pizza price calculator that keeps base, toppings, size, and tax responsibilities separate. Show how the components collaborate to compute a price without embedding every combination in one class.
### Constraints & Assumptions
No actual price list, tax jurisdiction, size multiplier, or topping limits are specified. Use configurable pricing policies and state the chosen calculation order.
### Clarifying Questions to Ask
- Does size change only the base price or also topping prices?
- Is tax applied to all components, and at which stage is rounding required?
- Are repeated toppings separate quantities or invalid duplicates?
```hint Separate choices from rules
A pizza describes what was ordered; pricing rules describe what those choices cost.
```
### What a Strong Answer Covers
- Separate representations for base, size, topping quantities, and tax policy.
- An explicit calculation order with decimal or minor-unit money arithmetic.
- Validation and a testable breakdown of subtotal, tax, and total.
- A way to change prices without rewriting pizza composition classes.
### Follow-up Questions
- Where would a topping-specific surcharge belong?
- How would you preserve the price paid for an order after a price-list update?
Overview: Design a pizza price calculator using separate base, topping, size, and tax policies, with accurate money arithmetic and a testable price breakdown.
Design an object-oriented pizza price calculator that keeps base, toppings, size, and tax responsibilities separate. Show how the components collaborate to compute a price without embedding every combination in one class.
Constraints & Assumptions
No actual price list, tax jurisdiction, size multiplier, or topping limits are specified. Use configurable pricing policies and state the chosen calculation order.
Clarifying Questions to Ask Guidance
Does size change only the base price or also topping prices?
Is tax applied to all components, and at which stage is rounding required?
Are repeated toppings separate quantities or invalid duplicates?
What a Strong Answer Covers Guidance
Separate representations for base, size, topping quantities, and tax policy.
An explicit calculation order with decimal or minor-unit money arithmetic.
Validation and a testable breakdown of subtotal, tax, and total.
A way to change prices without rewriting pizza composition classes.
Follow-up Questions Guidance
Where would a topping-specific surcharge belong?
How would you preserve the price paid for an order after a price-list update?