Parking Lot

Level: Intermediate

Concepts: Design State


Create a program to manage a parking lot system with different types of vehicles and parking spots.

Requirements

  1. Implement parking lot management:
    • Different types of vehicles (Motorcycle, Car, Bus)
    • Different types of parking spots (Motorcycle, Compact, Large)
    • Parking rules based on vehicle and spot types
    • Track available spots and parked vehicles
  2. Handle parking operations:
    • Park a vehicle (assign to appropriate spot)
    • Remove a vehicle (free up spot)
    • Check parking status
    • Find available spots
  3. Return appropriate results:
    • Success/failure of parking operations
    • Current parking lot status
    • Error messages for invalid operations

Test Cases

Scenario Input Expected Result Notes
Empty Lot Check status All spots available Initial state
Park Motorcycle Park motorcycle in motorcycle spot Success Fits in any spot
Park Car Park car in compact spot Success Fits in compact or large
Park Bus Park bus in large spot Success Needs 5 consecutive large spots
Invalid Park Park car in motorcycle spot Error Spot too small
Remove Vehicle Remove parked vehicle Success Frees up spot

Edge Cases to Consider

  • Parking lot is full
  • Vehicle already parked
  • Removing non-existent vehicle
  • Parking in occupied spot
  • Multiple vehicles of same type

Tips

  • Start with basic vehicle and spot types
  • Add parking rules next
  • Then implement spot management
  • Finally add status tracking
  • Consider using enums for vehicle and spot types