Extensible employee cost calculator
I was asked this
No reports yet. Sign in to say where you were asked it.
An object-oriented design interview question asked in Amazon's coding round, last asked Feb 2026. It tests object-oriented design and extensibility.
Design the object model and calculation API for what an employee costs the company. The total has four parts: base salary from the employee record; tax as a fixed percentage of base salary; benefits looked up by (level, title); and a location adjustment, positive or negative, looked up by location. New employee types and cost parts will be added later, so avoid a chain of conditionals.
Requirements
- Functional: compute the total and a line-by-line breakdown for one employee; fail clearly when a lookup entry is missing.
- Non-functional: exact money arithmetic in one currency per calculation; results reproducible after the rules change; easy to extend and to test.
Classes and operations
Unless you agree on a different design with the interviewer, assume:
Employee(id, base_salary: Money, level, title, location)-
CostComponentinterface:compute(employee, policy) -> LineItem; implementationsBaseSalary,Tax,Benefits,LocationAdjustment. -
CostPolicy(versioned): tax rate, benefits table, location table. -
CostCalculator(components).total(employee, policy) -> CostBreakdown— line items, total, policy version.
Example
policy v3: tax 10%; benefits (L5, "Engineer") = 12,000; location "NYC" = +8,000, "Remote" = -5,000
employee: base 150,000, L5, Engineer, NYC
total -> 150,000 + 15,000 + 12,000 + 8,000 = 185,000 (policy v3)
same employee in "Remote" -> 150,000 + 15,000 + 12,000 - 5,000 = 172,000
Clarifying questions
- Is tax really one fixed rate, or does it vary by employee or location?
- Should a missing benefits or location entry fail, count as zero, or fall back to a broader entry?
- Are adjustments annual amounts or percentages?
- What rounding and currency precision apply?
What a strong answer covers
- Employee data, policy configuration, lookup interfaces and the calculation kept separate.
-
Moneyin integer minor units or decimals, never binary floats. - A breakdown, not only a total.
- Missing configuration handled explicitly, with validated canonical keys for level, title and location.
- Versioned policies so a past result can be explained and reproduced.
- Tests for normal, boundary, negative-adjustment, missing-rule and rounding cases.
- Adding a contractor type or a new component as a new class, with the calculator unchanged.
Follow-ups
- Progressive tax brackets without changing callers.
- Effective-dated policy changes applied to historical calculations.
- Salary and adjustment in different currencies.
Where it's asked
- Amazon · Coding · Last asked Feb 202655 min · Usually two rounds; one is often an object-oriented design built in steps · No AI
What it tests
object-oriented design · extensibility
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
