Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
Concepts in System:
1. Machine
2. Item
3. Money
4. Keypad
5. ItemPicker
6. ColumnPusher
7. MoneyValidator / Counter
8. ItemSlot
9. Payment
Classes:
1. Machine
2. Item
3. Money
> Bill ($)
> Coin
4. Keypad
5. ItemPicker
--- lock/unlock
--- pushColumn
6. MoneyValidator / Counter
>> CashValidator
>> CardValidator
8. ItemSlot
9. MoneySlot
>> CashSlot
>> CardSlot
9. Inventory
key, Stack<Item>
key => ItemSlot
10. KeypadInterface
---- understand the payment mode, and call Validator and Payment classes
---- Validate the valid itemSlot and item is available or not
11. Can use Command Pattern to execute the command from user.
VendingCommand => SlotNumber
execute(..) =>
a. Will do the do the payment
b. Instruct ItemPicker ( provide the slot using
inventory)
c. Update the inventory
d. and say Cheers :)
---- Dev 2.0
I would use State Pattern to design a vending machine. I see this example in Head First in Design Patterns
- Collections.solutions() April 09, 2012