Question: Q : Subclass the BankAccount class from the previous question to create a MinBalanceBankAccount class. This class should require a minimum balance at all times

 Q: Subclass the BankAccount class from the previous question to create

Q: Subclass the BankAccount class from the previous question to create a MinBalanceBankAccount class. This class should require a minimum balance at all times and should raise an exception (of the type ValueError) when an attempt to drop the balance below the minimum occurs. The MinBalanceBankAccount should be instantiated with the account number, initial balance, and the minimum balance. No error checking against the minimum balance is necessary upon instantiation.

a = MinBalanceBankAccount(account_id=1, balance=100, minimum_balance=10) a.withdraw(100) ... ValueError: Sorry, minimum balance must be maintained.

If raised, the ValueError should have the message: 'Sorry, minimum balance must be maintained.'

A minimum of extra code should be implemented in __init__ and withdraw to meet the requirements of this question.

[2 points]

The previews code:

class BankAccount: def __init__(self, number, balance=0): self.account_number = number self.balance = balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount def __str__(self): return "Account ID: {} - Balance: {}".format(self.account_number, self.balance)

Q: Subclass the BankAccount class from the previous question to create a MinBalanceBankAccount class. This class should require a minimum balance at all times and should raise an exception of the type ValueError ) when an attempt to drop the balance below the minumum occurs. The MinBalanceBankAccount should be instantiated with the account number, inital balance, and the minimum balance. No error checking against the minimum balance is necessary upon instantiation. a = MinBalanceBankAccount (account_id=1, balance=100, minimum_balance=10) a. withdraw(100) ValueError: Sorry, minimum balance must be maintained. If raised, the ValueError should have the message: 'Sorry, minimum balance must be maintained.' A minimum of extra code should be implemented in _init_ and withdraw to meet the requirements of this question. [2 points)

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 Databases Questions!