Parking Lot

Mediumconcurrencystate machinestrategyidempotency

Design the software for a multi-floor parking lot that several entry gates use at the same time.

Requirements

  1. Spots and vehicles. Spots are SMALL, MEDIUM or LARGE. A BIKE fits any spot, a CAR fits MEDIUM or LARGE, and a TRUCK fits only LARGE. You choose which fitting spot to assign, but explain your allocation rule in comments.
  2. Park. park(plate, type, idempotencyKey) assigns a free spot and returns a ticket id.
    • Plates are case-insensitive and trimmed (" ka01 " is the same car as "KA01").
    • A plate that already has an active ticket is rejected with DuplicateVehicleException.
    • If no fitting spot is free, it throws ParkingFullException.
    • Retrying with the same idempotency key returns the same ticket id and does not take a second spot.
  3. Pay. pay(ticketId) returns the fee in paise: the rate for the vehicle type ร— the number of started hours, with a minimum of 1 hour. For example, 61 minutes is 2 hours and exactly 60 minutes is 1 hour. Read time only from the Clock given to Solution.create. Paying again returns the first fee and doesn't charge again.
  4. Exit. exit(ticketId) frees the spot. A ticket moves ACTIVE -> PAID -> EXITED:
    • exit before paying -> InvalidStateException
    • exit twice -> InvalidStateException
    • pay after exit -> InvalidStateException
    • unknown ticket -> NotFoundException
  5. Queries. spotOf(ticketId) returns the spot id held by an active ticket. freeSpots() returns the free count for every size.
  6. Validation. A blank plate or key is rejected with IllegalArgumentException. Solution.create rejects an invalid config (no floors, negative counts, a floor with zero spots, missing or negative rates) with IllegalArgumentException.

Non-functional requirements

What you get

Add as many classes and packages as you need. The judge scores correctness (hidden tests, including multi-threaded ones) and design quality (SOLID, extensibility, thread safety, input validation). Each counts for 50%.

com/lld/parkinglot/Solution.java
com.lld.parkinglot
Main.java
Solution.java
com.lld.parkinglot.api
๐Ÿ”’ DuplicateVehicleException.java
๐Ÿ”’ InvalidStateException.java
๐Ÿ”’ LotConfig.java
๐Ÿ”’ NotFoundException.java
๐Ÿ”’ ParkingException.java
๐Ÿ”’ ParkingFullException.java
๐Ÿ”’ ParkingLot.java
๐Ÿ”’ SpotSize.java
๐Ÿ”’ VehicleType.java
Loading...