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

How to approach it

What this question tests, where it gets hard, and how to spend the time.

Read the question

What this problem tests

  • Can you cut?

    Payment, booking, electric, valet: the prompt invites everything. Choose two verbs and do them well.

  • Can you find the owner?

    Who may hand out a space? One answer makes the rest easy.

  • Can you leave classes out?

    Say which nouns you reject. It sounds like experience because it is.

  • Can you see the gap?

    Between looking and taking, and between charging and releasing.

Think

Five questions before you draw

Ask yourselfHere
Who does what?A driver enters and leaves. A sign reads counts
What must never go wrong?One space for two cars, and a car that cannot leave
What is the hardest thing?Claiming, when several gates want the last space
What changes most?Prices
What am I giving up?An exact total across levels, if I split the lock

Time

Spend the 45 minutes

MinutesDoLeave withSkip
0 to 5Ask, write down the answersTwo verbs, three sizes, several gatesBooking, passes
5 to 10Nouns: keep and rejectSeven boxes and the reasonsGetters
10 to 18Class diagramState and public methodsBoth directions of each arrow
18 to 33Code: pool, enter, leaveRuns in your headPrinting, parsing
33 to 38Trace: full lot, declined cardOne bug found by you"It should work"
38 to 45Races, then one extensionWhich class changesA second full design

If you are stuck, go round this loop

Memory

PARK

Participants: vehicle, space, lot, ticket. Actions: enter, leave, claim, release. Relationships: the lot owns the pool, the ticket links vehicle and space. Key risks: the race, the price, the payment. Say them in this order and you have an outline.

Lines that help

  • "A level is a number until it owns something."
  • "Full is a result, not an exception."
  • "I will take the ticket out before I charge."
  • "Here is the sum that says one lock is enough."

Lines that hurt

  • "I will make it a Singleton, because there is one lot."
  • "I will add a factory, so it is extensible."
  • "We can make all methods synchronized." And the card?
  • "Then we put it in a database." That was not the question