Design Projects: Classic Systems · Design project
Design a Parking Lot System
A free design project from the Design a Parking Lot skill. Read it here, then solve it in the app in Java or Python.
- Medium
- Design project
- Free
- Java and Python
The problem
Problem Overview
A multi-level parking lot needs to admit vehicles into free spots, track which vehicles are currently parked, and free a spot back up when a vehicle leaves. This is a classic object-oriented design interview problem: unlike an algorithmic question, there's no single right function to write — you're designing a small set of collaborating classes and being graded on whether the system they form actually behaves correctly.
Functional Requirements
- Park an incoming vehicle in any compatible free spot, and return a ticket identifying that parking session.
- Reject a vehicle when no compatible spot is free (return
null-Nonein Python - rather than throwing). - Free a vehicle's spot given its ticket, and correctly reject an unknown/already-used ticket.
- Report how many spots of a given size are currently free.
- A vehicle fits exactly one spot size:
MOTORCYCLE->SMALL,CAR->MEDIUM,BUS->LARGE. - Each ticket is unique and frees its spot once; using it again returns
false(Falsein Python).
Project Layout
parkinglot/model/Vehicle.java(fixed) — a vehicle's type and license plate.parkinglot/model/ParkingSpot.java(fixed) — a single spot's size and occupied state.parkinglot/ParkingLot.java(you implement) — the public API under test; owns the collection of spots and the mapping from ticket to occupied spot. Keep its constructor and public methods.parkinglot/Main.java— a demo you can change freely; Run prints its output.- Your own classes can go anywhere under
parkinglot/exceptparkinglot/tests/— for example an allocation strategy inparkinglot/strategy/. - In Python the same layout is made of modules:
parkinglot/model/vehicle.pyandparking_spot.py(fixed - the enums areVehicleTypeandSpotSize),parkinglot/parking_lot.py(yours:park_vehicle,unpark_vehicle,available_spots) andparkinglot/main.py(the demo).
Run executes the sample tests in parkinglot/tests/ParkingLotSampleTest.java (Python:
parkinglot/tests/sample_test.py) and shows each
failure's message. Submit runs the hidden suite — pass/fail per test only — and is what's scored.
Patterns to Apply
- Encapsulation:
ParkingLotshould own spot-allocation logic entirely — callers never touch aParkingSpot's occupied flag directly. - A simple allocation strategy (first free compatible spot) is enough here; a
Strategypattern swap-in (e.g. nearest-spot, size-optimal) is a natural follow-up, not required.
Follow-up Questions (for discussion, not graded)
- How would you support multiple entry gates operating concurrently without double-allocating the same spot?
- How would per-duration pricing/billing extend this design without
ParkingLotneeding to know about payment details? - How would you generalize
ParkingSpot.Sizematching if a vehicle could fit in multiple spot sizes (e.g. a motorcycle fitting in any size)?
Constraints
- Do not change the signatures of
ParkingLot's public methods, or ofVehicle/ParkingSpot- the hidden tests are written against them exactly as given. - Assume single-threaded access - concurrency is a follow-up discussion question, not graded.
How it's graded
- You work in a small multi-file project. Run executes a sample test suite and your Main; Submit grades the project with a hidden suite.
- Stuck? Hints come in four steps, from a nudge to a code skeleton, each costing part of the points.
More problems in Design a Parking Lot
Solve it Design a Parking Lot System free
No card needed. Lessons, practice questions and easy problems are free forever.
Free plan, no card · 7-day Pro trial · Cancel anytime