Match day at Hilltop Garage

Design the classes for a multi-level parking lot

MediumAbout 45 minJava or TypeScript

Concepts this problem usesHidden, since spotting them is part of the practice.Show themHide
The garage · Saturday, 1:45 pm · kickoff at 3:007 spots free, 5 of them fit a car
LEVEL 3SSMMMMMLLLEVEL 2SSMMMMMLLLEVEL 1SSMMMMMLLQUEUE TO THE HIGHWAYSPACES 7STADIUM
Free spot TakenS, M, L: spot size

The garage

Three levels across from the stadium

Rosa Alvarez runs Hilltop Garage, a three-level car park across the road from the city stadium. On a weekday it is half empty. On match days, three hours before kickoff, the queue of cars reaches the highway.

Today an attendant walks every floor with a clipboard, hunting for a free spot that fits, writing tickets by hand and waving drivers up the ramp. When nothing fits, the driver is turned away, usually after ten minutes of searching. Rosa wants software doing that job before the season opener.

What Rosa wants

A spot, a ticket, a fair fee

Every level has small, medium and large spots. When a vehicle arrives it gets the first free spot that fits it, on any level, and a ticket; when nothing fits anywhere, it is turned away. When it leaves, its spot is freed for the next driver and the fee is worked out from the ticket. These are the prices and sizes posted at the gate:

Hilltop Garage · Rates

$4 every started hour

  • At least one hour is always charged
  • Never more than $50 per 24 hours
  • Several days: at most $50 for each 24 hours

Which spot fits

SML
Motorbike●●●
Car·●●
Truck··●

Last Saturday

Two tickets from match day

A car came early and left at half-time. A food truck arrived for the afternoon and stayed for Sunday's game too; the cap kept its fee down.

Ticket #1Car
Spot
M3 · level 1
In
Sat 1:10 pm
Out
Sat 3:25 pm
Stay
2 h 15 min → 3 h
3 × $4$12
Ticket #2Food truck
Spot
L1 · level 2
In
Sat 1:40 pm
Out
Sun 1:00 pm
Stay
23 h 20 min → 24 h
24 × $4, capped$96$50

Next season

Vans, weekend prices, and no rewrite

The city brings in electric vans next year, and I want weekend prices. I'm not paying for a rewrite either time.Rosa Alvarez

The card machine at the exit takes the money, so the software only works out the fee. There are no reservations or monthly passes to worry about.

Design the classes for Rosa's garage.

Start building