Create class SavingsAccount. 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 12- this interest should be added to savingsBalance. Provide a static method setInterestRate that sets the annualInterestRate to a new value. There should also be a method setSavingsBalance to set the initial savings balance for a new saver or you can do it through a constructor.

Write a program to test class SavingsAccount. Instantiate two SavingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for each 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next month's interest and print the new balances for both savers.

If you run this java file right now, it only prints out the amount for 1 month. How can you make my program so that it prints the amount for 13 months?

It should print out

Month 1: 2006.67

Month 2: 2013.36

Month 3: 2020.07

Month 4: 2026.80

etc.

after 12 month, change the rate to be 5 percent

Respuesta :

Answer:

import java.util.*;

public class Main{

public static double calculateMonthlyInterest(double annualInterestRate, double savingsBalance){

    double monthlyInterest = annualInterestRate * savingsBalance / 12;

    return monthlyInterest; }

public static double setInterestRate (){

    Scanner input = new Scanner(System.in);

    System.out.print("Interest Rate: ");

    double rate = input.nextDouble();

    return rate; }

public static double setSavingsBalance(double monthlyInterest, double savingsBalance){

    return (monthlyInterest+savingsBalance); }

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.print("Savings Balance: ");

    double savingsBalance = input.nextDouble();

 double annualInterestRate = setInterestRate();

 for(int i = 1;i<=12;i++){

 double monthlyInterest = calculateMonthlyInterest(annualInterestRate,savingsBalance);

 savingsBalance = setSavingsBalance(monthlyInterest,savingsBalance);

 System.out.printf("Month "+i+"  %.2f %n",savingsBalance);

 }

}

}

Explanation:

The java file stated in the question is not attached to the question; So, I answered the question from the scratch.

See attachment for program file where I used comments to explain some lines

Ver imagen MrRoyal
ACCESS MORE
EDU ACCESS