Vending Machine
Problem Statement
Design the Low-Level Design (LLD) of a Vending Machine system that dispenses products like snacks, beverages, and chocolates when a user inserts money and selects an item.
The design should model the core classes, interactions, and states of the vending machine — focusing on object-oriented design principles such as encapsulation, abstraction, and state
management.
🧠 Functional Requirements
Display Products
Accept Coins / Notes
Select Product
Dispense Product
Return Change
Cancel Transaction
Refill and Maintenance
🚫 Non-Functional Requirements
🧱 Suggested Classes
ClassResponsibility
VendingMachine
Central class managing the current state, product inventory, and transaction flow.
State (Interface)
Defines actions (insertCoin, selectProduct, dispenseProduct, refund, etc.).
IdleState, HasMoneyState, DispenseState, SoldOutState
Concrete implementations of different machine states.
Product
Represents an item with name, price, and quantity.
Inventory
Manages available products and their stock.
Coin / Note (Enum)
Represents denominations supported by the machine.
Transaction
Maintains information about the current transaction (amount inserted, selected item, etc.).
ChangeDispenser
Calculates and returns appropriate change.
Admin
Responsible for refilling and maintaining the machine.
🔄 Example Flow
1
2Machine displays:
3[A1: Coke ₹50] [A2: Chips ₹30] [A3: Candy ₹10]1
2Insert ₹50
3→ State changes from Idle → HasMoney1
2Select A2 (Chips ₹30)
3→ Machine dispenses Chips
4→ Returns ₹20 change
5→ State → Idle1
2User inserts ₹100
3Cancels transaction → Refund ₹100🧪 Example Input / Output
Input:
1
2Insert ₹100
3Select Product: A1 (Coke ₹50)Output:
1
2Dispensing Coke...
3Returning ₹50 change.
4Thank you!Input:
1
2Insert ₹10
3Select Product: A1 (Coke ₹50)Output:
1
2Insufficient balance. Please insert ₹40 more.⚙️ Constraints
🎯 Goals
Your design should:
✅ In short:
Design a modular, state-driven Vending Machine system that can accept money, dispense products, handle change, and allow for easy maintenance and refilling — demonstrating OOP and state management principles.