Design a Parking Lot
MediumReal World SystemsSingletonFactoryStrategy
Problem Statement
Design a parking lot system that can accommodate different types of vehicles. The system should be able to:
- Support multiple levels/floors
- Handle different vehicle types (Motorcycle, Car, Truck)
- Have different parking spot sizes (Small, Medium, Large)
- Issue and process parking tickets
- Calculate parking fees based on time
Design Requirements
Entities to identify:
ParkingLot— Main system entry point (Singleton)Level— A floor in the parking lotParkingSpot— Individual spot with size and availabilityVehicle— Abstract vehicle with subtypesParkingTicket— Issued on entry, used on exitFeeCalculator— Strategy for calculating fees
Key Behaviors:
parkVehicle(vehicle)→ returns aParkingTicketor null if fullunparkVehicle(ticket)→ returns the fee amountgetAvailableSpots()→ count of available spots- Vehicles can only park in appropriate-sized spots (Motorcycle → Small/Medium/Large, Car → Medium/Large, Truck → Large only)
!Constraints
- A parking lot has 1–5 levels
- Each level has 10–100 spots
- Spot sizes: Small (bikes), Medium (cars), Large (trucks/buses)
- Parking fee: $2/hour for Small, $4/hour for Medium, $6/hour for Large
- A vehicle must park in the smallest available spot that fits it
- The system must be thread-safe (assume concurrent access)
Output
Run your code to see output here.