CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 6 of 6 · 2 min read

Exercises

Easy

Easy 1: Write the rules (20 minutes)

Write six numbered requirements for an ATM and three questions you would ask.

Done when: six rules and three questions exist, and two things are marked out of scope.

Hint

Add what happens on a jam and on a blocked card.

Easy 2: Run the session (20 minutes)

Type the code and reproduce the first rows of the run table: wrong PIN, right PIN, balance and a withdrawal of 600.

Done when: you print "welcome", 50000 and three 200-notes.

Hint

Build the bank and the accounts before the machine.

Easy 3: Plan by hand (20 minutes)

With stock 500 x1, 200 x3 and 100 x0, work out payouts for 600, 700, 800 and 1000 by hand.

Done when: four answers are written, and you say which ones greedy would miss.

Hint

600 = 200 x3. 700 = 500 + 200. 800 = 200 x4 is not possible with only three.

Medium

Medium 1: Jam test (45 minutes)

Write a test with a dispenser that jams. Check balance, today's total and the note stock before and after.

Done when: all three values are unchanged and the message says the account was not charged.

Hint

A broken flag on the test dispenser is enough.

Medium 2: Limit policy (45 minutes)

Add a LimitPolicy returned by the bank so that two cards have different limits. Remove the constants from Atm.

Done when: one card is refused at 25,000 and the other accepts it.

Hint

The policy returns a per-transaction and a daily limit.

Medium 3: Two machines (45 minutes)

Run two threads that each withdraw 600 from an account with a balance of 1,000.

Done when: exactly one succeeds in 100 repeated runs, and the balance is never negative.

Hint

Both threads pass the early checks, and debit lets only one in.

Hard

Hard 1: Deposits (90 minutes)

Add deposit(amount) with an envelope-free note acceptor that counts notes. Credit the account only after counting. Handle a miscount fault.

Done when: a fault before the credit returns the cash and leaves the balance unchanged.

Hint

Count first, credit second.

Hard 2: Step log (90 minutes)

Record each step of a withdrawal (planned, debited, dispensed) in a log. Write a recovery routine that, given a log ending at "debited", credits the account back.

Done when: a simulated crash after the debit is recovered by the routine, and a test shows the balance restored.

Hint

A list of strings is enough for the log.

Hard 3: State classes (90 minutes)

Rewrite the session with the state pattern. Add a Maintenance state. Compare with the enum.

Done when: both versions pass the same tests, and a note says at which number of states the classes win.

Hint

Each state class has the methods the customer can call.