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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started