#C14004. Bank Account Manager
Bank Account Manager
Bank Account Manager
You are required to implement a simple bank account management system. In this system, each account has a unique account number, an owner's name, and a balance. You must support the following operations:
- CREATE: Create an account with a given account number, owner name, and initial balance.
- DEPOSIT: Deposit an amount into a given account. The amount must be positive, i.e., \(amount > 0\). Otherwise, a
ValueError
should be reported. - WITHDRAW: Withdraw an amount from a given account. The amount must be positive and the account balance must be sufficient. If \(amount \le 0\), report a
ValueError
; if the balance is insufficient, report anInsufficientFundsError
. - TRANSFER: Transfer an amount from one account to another. The transfer amount must be positive. If not, a
ValueError
is reported. The source account must have sufficient funds for the transfer. - BALANCE: Print the current balance of a given account.
For operations that encounter errors (such as depositing a non-positive amount, withdrawing with insufficient funds, or negative transfers), print the corresponding error message (ValueError
or InsufficientFundsError
) and continue processing subsequent commands.
All formulas are given in LaTeX format, for example, the condition for a valid deposit is \(amount > 0\).
inputFormat
The first line of input contains an integer \(Q\) representing the number of commands. Each of the following \(Q\) lines contains one of the following commands:
CREATE id owner initial_balance
DEPOSIT id amount
WITHDRAW id amount
TRANSFER from_id to_id amount
BALANCE id
- print the current balance of the account with id.
Note that id
is an integer and amount
and initial_balance
are floating point numbers. The owner
is a single word string.
outputFormat
For each BALANCE
command, print the current balance of the specified account on a separate line. For any operation that triggers an error (invalid deposit/withdraw/transfer amounts or insufficient funds), print the corresponding error message (ValueError
or InsufficientFundsError
) on a separate line.
7
CREATE 1 Alice 100.0
CREATE 2 Bob 50.0
DEPOSIT 1 50.0
WITHDRAW 2 10.0
TRANSFER 1 2 30.0
BALANCE 1
BALANCE 2
120.0
80.0
</p>