ParkingFloorParkingSpotcalculateFee(entryTime, exitTime)ParkingLot → contains → ParkingFloorParkingFloor → contains → ParkingSpotIf ParkingLot is deleted, everything goes away.
ParkingSpot → Small / Medium / LargeVehicle → Motorcycle / Car / TruckPricingStrategy → different strategiesParkingTicket → has → VehicleParkingTicket → has → ParkingSpotParkingLotManager depends on:ParkingLotPricingStrategyParkingLot → many ParkingFloorParkingFloor → many ParkingSpotParkingSpot → at most one VehicleFor each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation. Write your code in the code editor below.
Choice made:
Queue per SpotType → O(1) allocationTradeoff:
Alternative:
PriorityQueue (distance-based)Choice made:
synchronized at ParkingLotManagerReentrantLock at floor levelTradeoff:
Alternative:
SpotType or even per ParkingSpot✅ Better concurrencyChoice made:
HashMap<String, ParkingTicket> (in-memory)Tradeoff:
Alternative:
Choice made:
Tradeoff:
Alternative:
✔ Mostly followed:
ParkingFloor → manages spotsParkingLotManager → orchestrates parkingPricingStrategy → fee logic⚠️ Minor issue:
ParkingLotManager does multiple things:👉 Improvement:
SpotAllocatorTicketService✔ Well followed:
PricingStrategyVehicle❌ Slight violation:
switch👉 Improvement:
vehicle.getAllowedSpotTypes()
✔ Fully followed:
Car, Truck can replace VehicleSmallSpot, LargeSpot behave consistently✔ Good:
PricingStrategy is clean and minimalCould improve:
AllocatableBillablePartially followed:
PricingStrategy abstraction ✅But:
ParkingLotManager directly depends on ParkingFloor👉 Improvement:
interface SpotAllocator
VEHICLE_PARKEDVEHICLE_EXITED✅ Add new pricing:
class WeekendPricing implements PricingStrategy
✅ Add EV charging spots:
EVSpot extends ParkingSpot✅ Add reservations:
ReservationServicePaymentService👉 “The design prioritizes simplicity and O(1) allocation using queues, while maintaining extensibility through strategy patterns. It adheres well to SOLID principles with minor improvements possible around SRP and DIP. For scaling, we can move to distributed services with caching and event-driven architecture. The system is easily extensible for features like reservations, EV spots, and dynamic pricing.”