← Questions

Design an ATM: card, PIN, balance, withdrawals and deposits

0
AmazonOO design

Design the software for an ATM. A customer inserts a card and enters a PIN, then checks the balance, withdraws cash, or deposits. The machine has a cash dispenser holding notes of fixed denominations, talks to the bank to authorize every transaction, and must behave safely when anything fails part way.

Requirements

  • Functional: read the card and verify the PIN with the bank, with a limit on wrong attempts before the card is retained; show the account balance; withdraw an amount, checked against the balance, the daily limit and whether the dispenser can make it from the notes it holds; deposit cash or cheques; print or show a receipt; end the session and return the card.
  • Non-functional: money is never lost: if the dispenser fails after the bank debits the account, the debit is reversed; every transaction is logged; the machine goes out of service when cash runs out or a part fails.

Clarifying questions

  • Which note denominations, and should the machine prefer large or small notes?
  • Is the bank connection always available? What happens while it is down?
  • Does the ATM serve several banks' cards (with fees)?
  • Are deposits counted by the machine, or checked later by the bank?
  • Can a customer do several transactions in one session?

What a strong answer covers

  • Core classes: ATM (the controller), CardReader, Keypad, Screen, CashDispenser (notes per denomination, can_dispense, dispense), DepositSlot, ReceiptPrinter, BankService (the interface to the bank), Session (card, account, attempts), and Transaction with BalanceInquiry, Withdrawal and Deposit.
  • ATM states (idle, card inserted, authenticated, transaction in progress, out of service) using the state pattern.
  • Withdrawal as two phases: check locally that the notes can make the amount, authorize and hold with the bank, dispense, then confirm; on dispenser failure, reverse the hold.
  • Note selection with limited notes per denomination, refusing an amount the machine cannot make.
  • Hardware behind interfaces so the logic is testable with fakes, and a transaction log for reconciliation.
  • Tests: wrong PIN three times, an amount that cannot be made, a dispenser jam after authorization.

Follow-ups

  • Add cardless withdrawal with a code from a phone app.
  • The bank link drops mid-withdrawal. What does the ATM do, and how is it reconciled?
  • Track cash levels and alert the operator before the machine runs out.
Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing