Question: In Python, Write the following 2 classes. The names in bold must match. Bank Account In addition to these classes you will need to create

In Python, Write the following 2 classes. The names in bold must match.
Bank
Account
In addition to these classes you will need to create the following exception classes that inherit from Exception class in python. The following exception classes need to be created.
AccountNotFoundError
InvalidStartingBalanceError
InvalidAmountError
NonZeroAccountBalanceError
InsufficientBalanceError
Attributes
The Bank class will have the following attributes.
Bank Name. This will be String.
List of accounts. This will be a list of Account objects.
Account Sequence. Starting account number. Everytime a new account is created, the sequence number will be used as the account number and the sequence will be incremented by 1. This ensures that all account numbers are unique. Maintaining the sequence at Bank level ensures that all accounts have unique account numbers. Default value will be 1000.
The Account class will have the following attributes.
Account number : Unique account number generated from Account Sequence.
Balance : Default value is 0. Must be a double.
Methods:
Methods in the Bank class are as follows.
Constructor (Name) :
Name : String
This constructor will accept one mandatory argument which would be assigned to the bank name.
createAccount(initialDeposit)
startingBalance: double
Create a new account object using the Account Sequence in the Bank object to assign an account number. Add the account to the list of accounts in the bank. Increment the account sequence to avoid duplicates.
lookupAccount(accountNumber)
accountNumber : int
Look up the account number in the account list. Raise AccountNotFoundError if the account is not found. Return the looked up account.
closeAccount(accountNumber)
accountNumber : int
Look up the account number in the account list. Raise AccountNotFoundError if the account is not found. Check if the account balance is 0. If the account balance is not zero then raise NonZeroAccountBalanceError. If the account balance is 0 then remove the account from the list of accounts held in the bank.
deposit(accountNumber, amount)
accountNumber: int
Amount: float
Lookup account by accountNumber in the list of accounts. If the account exists then add the amount to the account balance. This can be done by calling the deposit method on account. If the account is not in the account list then raise AccountNotFoundError.
withdraw(accountNumber, amount)
accountNumber: int
Lookup account by accountNumber in the list of accounts. If the account is not in the account list then raise AccountNotFoundError. If the account exists then subtract the amount from the account by calling the withdraw method on the account. Note the withdraw method may throw InsufficientBalanceError.
__str__()
Returns a string with the bank's name, number of accounts and total deposits.
Methods in the Account class are as follows.
Constructor (accountNumber, startingBalance) :
accountNumber: int
startingBalance: double
Check the startingBalance. If the startingBalance<=0 then raise InvalidStartingBalanceError. If the starting balance is fine then assign the values directly to the attributes to create the account.
deposit(amount)
amount : double
Check the amount. If the amount <=0 then raise InvalidAmountError. If the amount is fine then add the value to the account balance.
withdraw(amount)
amount : double
Check the amount. If the amount <=0 then raise InvalidAmountError. If the amount is fine then check the account balance. If the account balance is >= amount then subtract the amount from the account balance. Raise InsufficientBalanceError if the amount is greater than balance.
__str__()
Return a string containing the account number and current balance. See example below. The balance is displayed up to two decimal places.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!