Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help writing a java program. I need help to complete part 2 of this prompt. I ha

ID: 3722197 • Letter: H

Question

Help writing a java program.

I need help to complete part 2 of this prompt. I have completed part 1, which I have included, below.

_____________________________________________________________________________________________________________________________________________________

Part 1 – COMPLETED Code included below

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 using a scanner and show balance and interest earned for each account.

Some Tips for helping you with Lab 4:

You need to write deposit and withdrawal methods. Should you put this in parent class or child class? Try to answer this question so that you have most reusability in your class definition.

In this part - you have to learn how polymorphism works.

You will have accounts whose balance might be above or below 10K. By using methods in both classes try to change the interest earned to 10% if balance is above 10K or 4% if the interest is lower.

public class SpecialSavings extends SavingAcct{
//override - calcMonthlyInterest()
//if balance > 10K then set interest rate to 10% and the call super.calcMonthlyInterest()
//reset the rate back to what it should be.
//keep in mind you are modifying static variable.
}
public class Driver2 {
//test SpecialSavings
}

______________________________________________________________________________________________________________________________________

import account.SavingsAccount;

public class Driver1

{

public static void main (String args [])

{

SavingsAccount saver1=new SavingsAccount (2000);

SavingsAccount saver2=new SavingsAccount (3000);

SavingsAccount.modifyInterestRate (0.04);

System.out.printf("*************************************** ");

System.out.printf("* Monthly Balances for one year at 4%% * ");

System.out.printf("*************************************** ");

System.out.println("Balances: ");

System.out.printf("%20s%10s ","saver1","saver2");

System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

for (int month=1; month<=12; month++)

{

String monthLabel=String.format("Month %d:", month);

saver1.calculateMonthlyInterest ();

saver2.calculateMonthlyInterest ();

System.out.printf("%-10s%10s%10s ", monthLabel,saver1.toString (),saver2.toString ());

}

//SavingsAccount.modifyInterestRate (0.05);

//saver1.calculateMonthlyInterest();

//saver2.calculateMonthlyInterest();

System.out.printf(" ***************************************** ");

System.out.printf("* After setting the interest rate to 5%% * ");

System.out.printf("***************************************** ");

System.out.printf("Balances: ");

System.out.printf("%20s%10s ", "saver1", "saver2");

System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

//applies 5 percent interest to last balance of accounts saver1 and saver2

for (int month=1; month<=12; month++)

{

String monthLabel=String.format("Month %d:", month);

SavingsAccount.modifyInterestRate (0.05);

saver1.calculateMonthlyInterest ();

saver2.calculateMonthlyInterest ();

System.out.printf("%-10s%10s%10s ",monthLabel,saver1.toString (),saver2.toString ());

}

}

}

_____________________________________________________________________________________________________________________

package account;

public class SavingsAccount

{

//interest rate for all accounts

private static double annualInterestRate=0;

private double savingsBalance;

//Constructor that creates a new account with the specified balance

public SavingsAccount (double balance)

{

savingsBalance=balance;

}

//get monthly interest

public void calculateMonthlyInterest ()

{

savingsBalance += savingsBalance*(annualInterestRate/12.0);

}

//modify the interest rate

public static void modifyInterestRate (double newRate)

{

annualInterestRate=(newRate>=0 && newRate<=1.0)?newRate:0.04;

}

//

public String toString ()

{

return String.format ("$%.2f", savingsBalance);

}

}

Explanation / Answer

package account;

public class SavingsAccount {

       //interest rate for all accounts

       private static double annualInterestRate=0;

       private double savingsBalance;

       //Constructor that creates a new account with the specified balance

       public SavingsAccount (double balance)

       {

       savingsBalance=balance;

       }

       //get monthly interest

       public void calculateMonthlyInterest ()

       {

       savingsBalance += savingsBalance*(annualInterestRate/12.0);

       }

       //modify the interest rate

       public static void modifyInterestRate (double newRate)

       {

       annualInterestRate=(newRate>=0 && newRate<=1.0)?newRate:0.04;

       }

       //

       public String toString ()

       {

       return String.format ("$%.2f", savingsBalance);

       }

}

import account.SavingsAccount;

public class Driver1 {

       public static void main (String args [])

       {

       SavingsAccount saver1=new SavingsAccount (2000);

       SavingsAccount saver2=new SavingsAccount (3000);

       SavingsAccount.modifyInterestRate (0.04);

       System.out.printf("*************************************** ");

       System.out.printf("* Monthly Balances for one year at 4%% * ");

       System.out.printf("*************************************** ");

       System.out.println("Balances: ");

       System.out.printf("%20s%10s ","saver1","saver2");

       System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

       for (int month=1; month<=12; month++)

       {

       String monthLabel=String.format("Month %d:", month);

       saver1.calculateMonthlyInterest ();

       saver2.calculateMonthlyInterest ();

       System.out.printf("%-10s%10s%10s ", monthLabel,saver1.toString (),saver2.toString ());

       }

       //SavingsAccount.modifyInterestRate (0.05);

       //saver1.calculateMonthlyInterest();

       //saver2.calculateMonthlyInterest();

       System.out.printf(" ***************************************** ");

       System.out.printf("* After setting the interest rate to 5%% * ");

       System.out.printf("***************************************** ");

       System.out.printf("Balances: ");

       System.out.printf("%20s%10s ", "saver1", "saver2");

       System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

       //applies 5 percent interest to last balance of accounts saver1 and saver2

       for (int month=1; month<=12; month++)

       {

       String monthLabel=String.format("Month %d:", month);

       SavingsAccount.modifyInterestRate (0.05);

       saver1.calculateMonthlyInterest ();

       saver2.calculateMonthlyInterest ();

       System.out.printf("%-10s%10s%10s ",monthLabel,saver1.toString (),saver2.toString ());

       }

       }

}

import account.SavingsAccount;

public class Driver2 {

       public static void main(String[] args) {

              // TODO Auto-generated method stub

              SavingsAccount saver1=new SavingsAccount (2000);

              SavingsAccount saver2=new SavingsAccount (3000);

              SavingsAccount.modifyInterestRate (0.10);

              System.out.printf("*************************************** ");

              System.out.printf("* Monthly Balances for one year at 10%% * ");

              System.out.printf("*************************************** ");

              System.out.println("Balances: ");

              System.out.printf("%20s%10s ","saver1","saver2");

              System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

              for (int month=1; month<=12; month++)

              {

              String monthLabel=String.format("Month %d:", month);

              saver1.calculateMonthlyInterest ();

              saver2.calculateMonthlyInterest ();

              System.out.printf("%-10s%10s%10s ", monthLabel,saver1.toString (),saver2.toString ());

              }

              //SavingsAccount.modifyInterestRate (0.05);

              //saver1.calculateMonthlyInterest();

              //saver2.calculateMonthlyInterest();

              System.out.printf(" ***************************************** ");

              System.out.printf("* After setting the interest rate to 10%% * ");

              System.out.printf("***************************************** ");

              System.out.printf("Balances: ");

              System.out.printf("%20s%10s ", "saver1", "saver2");

              System.out.printf("%-10s%10s%10s ","Base",saver1.toString(),saver2.toString());

              //applies 5 percent interest to last balance of accounts saver1 and saver2

              for (int month=1; month<=12; month++)

              {

              String monthLabel=String.format("Month %d:", month);

              SavingsAccount.modifyInterestRate (0.10);

              saver1.calculateMonthlyInterest ();

              saver2.calculateMonthlyInterest ();

              System.out.printf("%-10s%10s%10s ",monthLabel,saver1.toString (),saver2.toString ());

              }

              }

       }

import account.SavingsAccount;

public class SpecialSavings extends SavingsAccount {

       @Override

       public void calculateMonthlyInterest() {

              // TODO Auto-generated method stub

                           super.calculateMonthlyInterest();

       }

      

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote