Exercise 1 Part 1 Create a class SavingsAccount. Use a static class variable to
ID: 3929411 • Letter: E
Question
Exercise 1 Part 1 Create a class SavingsAccount. Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a driver program to test the class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% and calculate the next months interest and print the new balances for each of the savers. Part 2 Write another class SpecialSavings that extends SavingsAccount to pay interest of 10% on accounts that have balances that exceed 10K. Also provided methods to deposit and take money out of savings account. Write a driver program to test the class SpecialSavings. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Make a few deposits and withdrawals and show balance and interest earned for each account.
Explanation / Answer
Please find the required program along with its output. Please see the comments against each line to understand the step.
-----------------------------------------------------
OUTPUT:
TEST1:
MonthlyInterest of saver1 = 666.6666666666666
MonthlyInterest of saver2 = 1000.0
MonthlyInterest of saver1 for next month = 666.6666666666666
MonthlyInterest of saver2 for next month = 1000.0
TEST2:
Saver1 balance: 2600.0
Saver1 interest: 866.6666666666666
Saver2 balance: 4400.0
Saver2 interest: 1466.6666666666667
Saver1 balance: 2600.0
Saver1 interest: 866.6666666666666
Saver2 balance: 4400.0
Saver2 interest: 1466.6666666666667
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.