Question: you will create a simple SavingsAccount class that includes a constructor with an exception handler, private and static variables, two calculation methods, a set method,
you will create a simple SavingsAccount class that includes a constructor with an exception handler, private and static variables, two calculation methods, a set method, and a test harness. harness. Specifications Create a class called SavingsAccount. Include an exception in the constructor to test for balances before zero (IllegalArgumentException). Use a static variable annualInterestRate to store the annual interest rate for all account holders. 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 savingsBalance by annualInterestRate divided by 12this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Include an exception in this method to ensure the rate is between 0.0 and 1.0. Write a program to test class SavingsAccount name it SavingsAccountTest. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Insert a printf statement after instantiating the above. with your student ID and name. Set annualInterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Now, set the annualInterestRate to 5%, calculate the next months interest and print the new balances for both savers. Finally, set the parameters for both methods, one at a time, so that an exception is thrown. Sample Output Monthly balances for one year at .04 Balances: Saver 1 Saver 2 Base $2000.00 $3000.00 Month 1: $2006.67 $3010.00 Month 2: $2013.36 $3020.03 Month 3: $2020.07 $3030.10 Month 4: $2026.80 $3040.20 Month 5: $2033.56 $3050.33 Month 6: $2040.33 $3060.50 Month 7: $2047.14 $3070.70 Month 8: $2053.96 $3080.94 Month 9: $2060.81 $3091.21 Month 10: $2067.68 $3101.51 Month 11: $2074.57 $3111.85 Month 12: $2081.48 $3122.22 After setting interest rate to .05 and calculating monthly interest Balances: Saver 1 Saver 2 $2090.16 $3135.23
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
