Question
Need help completeing part 2 of the below question. I have completed part one (which is included below). _____________________________________________________________________________________________________________________________________________________ Part 1 Create a class SavingsAccount.
Need help completeing part 2 of the below question. I have completed part one (which is included below).
_____________________________________________________________________________________________________________________________________________________
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.
_____________________________________________________________________________________________________________________________________________________
______________________________________________________________________________________________________________________________________
package account;
public class SavingsAccount
{
//variable to store the annual interest rate
static private double annualInterestRate;
private double savingBalance;
//Constructor method
public SavingsAccount()
{
this.savingBalance=0;
}
//Constructor method
public SavingsAccount(double savingBalance)
{
this.savingBalance=savingBalance;
}
//Get saving balance
public double getSavingBalance()
{
return this.savingBalance;
}
public double[] getMonthsSavingBalance(int total_months)
{
double[] monthlyI_month=new double[total_months];
double monthlyI;
for(int i=0;i { monthlyI= (double)(this.savingBalance*annualInterestRate/12); this.savingBalance+=monthlyI; monthlyI_month[i]=this.savingBalance; } return monthlyI_month; } // Modify interest rate by setting annual interest rate to a new value public static void modifyInterestRate(double newInterestRate) { annualInterestRate=newInterestRate; } //Method to calculate monthly interest public void calculateMonthlyInterest() { double monthlyI; monthlyI= (double)(this.savingBalance*annualInterestRate/12); this.savingBalance+=monthlyI; } } _______________________________________________________________________________________________________________________________________ import account.SavingsAccount; public class Driver1 { public static void main(String[] args) { SavingsAccount saver1,saver2; saver1 = new SavingsAccount (2000.0); saver2 = new SavingsAccount (3000.0); int total = 0; SavingsAccount.modifyInterestRate (0.04); int total_month=12; double[] balance_month=saver1.getMonthsSavingBalance(total_month); System.out.printf("********************************************************************" + "************* "); System.out.printf("*Savings Account 1's Projected Balance for the Year with an interest " + "rate of 4 %%* "); System.out.printf("********************************************************************" + "************* "); for(int i=0;i { System.out.printf("Month "+(i+1)+": "+balance_month[i]+ " " ); } System.out.printf(" ********************************************************************" + "************* "); balance_month=saver2.getMonthsSavingBalance(12); System.out.printf("*Savings Account 2's Projected Balance for the Year with an interest " + "rate of 4 %%* "); System.out.printf("********************************************************************" + "************* "); for(int i=0;i { System.out.printf("Month "+(i+1)+": "+balance_month[i]+" " ); } System.out.printf(" ********************************************************************" + "************* "); SavingsAccount.modifyInterestRate(0.05); balance_month=saver1.getMonthsSavingBalance(12); System.out.printf("*Savings Account 1's Projected Balance for the Year with an interest " + "rate of 5 %%* "); System.out.printf("********************************************************************" + "************* "); for(int i=0;i { System.out.printf("Month "+(i+1)+": "+balance_month[i]+" " ); } System.out.printf(" ********************************************************************" + "************* "); balance_month=saver2.getMonthsSavingBalance(12); System.out.printf("*Savings Account 2's Projected Balance for the Year with an interest " + "rate of 5 %%* "); System.out.printf("********************************************************************" + "************* "); for(int i=0;i { System.out.printf("Month "+(i+1)+": "+balance_month[i]+" " ); } System.out.printf("********************************************************************" + "* "); } }
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