Write a basic class that simulates a bank account that supports the following options:…
- User
Write a basic class that simulates a bank account that supports the following options:
Customers can deposit and withdraw funds. If sufficient funds are not available for withdrawal, a $10.00 overdraft penalty is charged. Once within a given month, interest can be added to the account. The interest rate can vary every month. Class BankAccount
Instance Members:
balance last_interest_date Instance Methods
constructor - Constructs a bank account with a given balance. Provides the default parameter initial_balance (default balance = Decimal("0.0"). deposit - Deposits money into the account. Takes the parameter amount to deposit. withdraw - Makes a withdrawal from the account or charges a penalty if sufficient funds are not available. Takes the parameter amount to withdraw. add_interest - Adds interest once monthly to a positive account balance. Takes the parameter rate that represents the current rate of interest (for allowable rate of interest 1% <= rate <= 2%). Monitor the date and only apply the rate calculation once monthly. get_balance - Returns the current account balance. Input Error Checking: Mutators must validate parameter data before writing to private instance fields. If parameter data is invalid there is no change in state of the bank account.
- Assistant
Here's a basic implementation of the class
BankAccountin Python that supports the options described:python - User
For the BankAccount class written previously. Provide a test driver that includes at minimum the following actions in the order as shown below:
Instantiate a bank account with an original balance of 500.00 Withdraws 125,000.99 Withdraws 126,500.00 Withdraws $10.00 Adds 1% interest Show the account balance after each action.
- Assistant
Here is a test driver that performs the actions described above:
cssfrom BankAccount import BankAccount def main(): account = BankAccount(Decimal("1000.00")) print("Balance after instantiation:", account.get_balance()) account.deposit(Decimal("500.00")) print("Balance after deposit of $500.00:", account.get_balance()) account.withdraw(Decimal("2000.00")) print("Balance after withdraw of $2000.00:", account.get_balance()) account.add_interest(Decimal("0.01")) print("Balance after adding 1% interest:", account.get_balance()) account.add_interest(Decimal("0.02")) print("Balance after adding 2% interest:", account.get_balance()) account.deposit(Decimal("125000.99")) print("Balance after deposit of $125,000.99:", account.get_balance()) account.withdraw(Decimal("0.99")) print("Balance after withdraw of $0.99:", account.get_balance()) account.withdraw(Decimal("126500.00")) print("Balance after withdraw of $126,500.00:", account.get_balance()) account.withdraw(Decimal("10.00")) print("Balance after withdraw of $10.00:", account.get_balance()) account.add_interest(Decimal("0.01")) print("Balance after adding 1% interest:", account.get_balance()) if __name__ == "__main__": main()