Projects · 13 / 19 Exercise Hard

Bank with OOP and exceptions

Objective

A bank with classes (Account and Bank) and its own exception hierarchy: each possible error is a subclass of a base error, and the main program catches them all with a single except.

Instructions

  • The first line has the number n of commands: open name, deposit name amount, withdraw name amount, transfer source target amount or balance name. Amounts are integers.
  • Each successful command shows OK, except balance, which shows name: balance. Errors show Error: message with: account not found, duplicate account, invalid amount (zero or negative amount) or insufficient balance.
  • A failed transfer must not change any balance. Check first that both accounts exist.
Input
5
open ana
deposit ana 100
withdraw ana 30
balance ana
withdraw ana 500
Output
OK
OK
OK
ana: 70
Error: insufficient balance

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise