AlgoViz

Design a parking lot

medium 90 min

Model a car park with several levels as classes: vehicles, spaces of different sizes, tickets and a replaceable price rule.

Watch lesson4:48

Sequence

Who calls whom, case by case

The point: one diagram per case that could go differently. If you can draw all seven, the code writes itself.

Case 1

Entry and parking

A car enters

The barrier opens after the lock is released. Hardware is slow, and the lot must not wait for it.

Case 2

What is free?

A sign asks

With several levels the lot adds up the levels. A sign may be a second old. A claim may not.

Cases 3 and 4

Exit, and paying

130 minutes in a medium space

Cash, card or phone: all are behind Payments. The lot cannot tell them apart.

The card is declined

Case 5

The ticket is lost

Found by plate

Never open on a spoken plate alone: the desk checks the car. Not found at all: one full day plus handling, for example 5000 + 2000 = 7000 cents.

Case 6

The lot is full

A polite no

Full for cars does not mean full for motorcycles. The answer is per vehicle.

Case 7

An electric car

A space with a charger

Parking and charging are two meters with one ticket. The charger is not inside Spot.

Who takes part

ParticipantRoleIn our code
DriverPersonNot modelled
Gate or panelCaller with hardwareOutside the lot
LotCoordinatorParkingLot
FloorNumber, or owner of a lockSpot.level, later Level
Space and poolThe scarce thing and its ownerSpot, SpotPool
TicketMemory of one stayTicket
SignReader or listenerfree()
PaymentSomebody else's machinePayments