Requirements


Functional Requirements:


  • Assign first-fitting spot - On arrival, find the earliest free spot that can fit the vehicle size across floors.
  • Issue ticket on entry - Generate unique ticket with vehicle, spot, and entry time.
  • Compute fee on exit - Calculate duration and apply active PricingStrategy.
  • Lot full handling - If no suitable spot exists, indicate 'Lot Full'.


Core Objects & Relationships


Main ParkingLot orchestrator to track number of vehicles per floor. It'll have an array of floors.


Class Floor that will contain an array of ParkingSpot, as well as a value to indicate if the floor is full.


Class ParkingSpot will contains the size of the vehicle allowed, a member to track state of the spot (whether it's empty or occupied), and maybe a time member to track how long it has been since the spot is occupied.


We'll also have a Vehicle class, a Ticket class to get entry time, and a PricingStrategy class.


APIs & Class Members

For 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.



Deep Dive


Each class has a single responsibility:

ParkingSpot -> state only

PricingStrategy -> pricing only

ParkingLot -> orchestration


You can easily add new vehicle types and new pricing strategies.