Design a Parking Lot

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-09

Problem Statement

Design the Low-Level Design (LLD) of a Parking Lot Management System that can manage entry, parking, and exit of vehicles efficiently.


The system should handle multiple parking floors, different vehicle types, and parking ticket generation, ensuring optimal use of parking slots and smooth vehicle flow.


Your goal is to focus on object modeling, class design, and interaction logic, not large-scale system architecture.


🎯 Goal


Design a system that can:


•Handle vehicle entry, parking slot allocation, and exit.
•Support different vehicle types (bike, car, truck, etc.).
•Manage multiple parking levels/floors.
•Generate tickets for each parked vehicle.
•Compute parking charges at exit.


✅ Functional Requirements


1. Parking Lot Setup


•The parking lot has multiple floors.
•Each floor has multiple parking slots.
•Each slot is designed for a specific vehicle type (Bike, Car, Truck).
•Track the availability of slots per floor and vehicle type.


2. Vehicle Entry


•When a vehicle arrives:
•Identify vehicle type.
•Check for an available slot.
•Allocate the nearest available slot.
•Generate a Parking Ticket containing:
•Entry time
•Slot ID
•Vehicle details
•Ticket ID


If the lot is full → return “Parking Full”.


3. Vehicle Exit


•When the vehicle leaves:
•User provides the ticket.
•System calculates parking duration.
•Compute parking fee based on rate and duration.
•Mark the slot as available again.


4. Fee Calculation


•Fee rules differ by vehicle type:
•Bike: ₹10/hour
•Car: ₹20/hour
•Truck: ₹50/hour
•Support extensions for dynamic pricing or flat rates.


5. Search & Status


•Show available slots per floor and vehicle type.
•Support operations:
•Get total available slots.
•Find where a vehicle is parked using registration number.


⚙️ Non-Functional Requirements


•Thread-safe slot allocation (no double booking).
•Extensible for future features (e.g., EV charging, online payment).
•Maintainable code with clear OOP separation.
•Low-latency for entry and exit operations.


🧱 Key Classes to Design


ClassResponsibility


ParkingLot


Central class managing all floors, slots, and ticketing.


ParkingFloor


Contains multiple slots and tracks availability.


ParkingSlot


Represents an individual parking space (id, type, status).


Vehicle


Represents a vehicle (number, type, owner).


Ticket


Represents issued ticket (ticketId, entryTime, vehicle, slot).


ExitGate


Handles fee calculation and slot release.


FeeCalculator


Computes parking charge based on duration and vehicle type.


ParkingManager


Orchestrates slot assignment, entry, and exit operations.


🧩 Example Class Relationships

1 2ParkingLot 3 ├── List<ParkingFloor> 4 ├── issueTicket(Vehicle) 5 ├── exitVehicle(Ticket) 6 7ParkingFloor 8 ├── int floorNumber 9 ├── List<ParkingSlot> 10 11ParkingSlot 12 ├── String id 13 ├── VehicleType type 14 ├── boolean isAvailable 15 16Vehicle 17 ├── String registrationNumber 18 ├── VehicleType type 19 20Ticket 21 ├── String ticketId 22 ├── Vehicle vehicle 23 ├── ParkingSlot slot 24 ├── Date entryTime 25 ├── Date exitTime


🔄 Example Flow


Input:

1 2Vehicle: KA-01-AB-1234 (Car)


Process:


1.System searches nearest available car slot.
2.Allocates Floor 1 - Slot C12.
3.Generates Ticket:
1 2Ticket ID: T001 3Entry Time: 10:00 AM 4Vehicle: KA-01-AB-1234 5Slot: F1-C12


Exit at 1:30 PM


•Duration = 3.5 hours
•Fee = ₹20 × 4 = ₹80 (rounded up)
•Slot F1-C12 marked available again.


Output:

1 2Payment Successful: ₹80 3Thank you! Visit again.


🔐 Concurrency Example


If multiple cars arrive simultaneously:


•Use synchronized access or a lock on slot assignment.
•Only one vehicle can occupy a slot at a time.


🧠 Possible Extensions


•EV charging slots.
•Dynamic pricing (based on demand/time).
•Online booking and reservation.
•Support for smart sensors to detect slot occupancy.
•Multi-entry gates with distributed control.


✅ Summary:


Design an object-oriented Parking Lot system (LLD) that:


•Supports multi-floor parking,
•Manages vehicle entry and exit,
•Allocates/release slots safely,
•Calculates parking fees.


Focus on class relationships, slot allocation logic, and thread-safe booking.

Solution

Comments