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

Overall Requirements Write a program that establishes two savings accounts with

ID: 3628394 • Letter: O

Question

Overall Requirements



Write a program that establishes two savings accounts with saver1 having account number 10002 with an initial balance of $2,000, and saver2 having account 10003 with an initial balance of $3,000. Set a common rate of interest at 5% per year. At the end of each month, update the balance by adding one month’s interest to the balance, so that the balance compounds monthly. Print an output that displays the month number and the account number and the balance for each of the two accounts. Use month 0 to display the initial balances, month 1 to display the balances after the first month’s interest, and so on. At the end of the year, display the total balance for both accounts combined, like this:







Output:



Monthly balances for one year with 0.05 annual interest:



Month Account # Balance Account # Balance

----- --------- ------- --------- -------

0 10002 2000.00 10003 3000.00

1 10002 2008.33 10003 3012.50

2 10002 2016.70 10003 3025.05

3 10002 2025.10 10003 3037.66

4 10002 2033.54 10003 3050.31

5 10002 2042.02 10003 3063.02

6 10002 2050.52 10003 3075.79

7 10002 2059.07 10003 3088.60

8 10002 2067.65 10003 3101.47

9 10002 2076.26 10003 3114.39

10 10002 2084.91 10003 3127.37

11 10002 2093.60 10003 3140.40

12 10002 2102.32 10003 3153.49



Final balance of both accounts combined: 5255.81



Use two classes, a SavingsAccount class and a YourNameProg4 as your Driver class.

8



SavingsAccount.java class



In the SavingsAccount class, declare a class variable called annualInterestRate, an instance constant called ACCOUNT_NUMBER, and an instance variable called balance. Provide a two-parameter constructor to initialize the instance constant and instance variable, and provide accessors for the instance constant and instance variable. Provide an addMonthlyInterest method to update the balance, by adding (balance * annualInterestRate / 12) to the current balance.







You are also required to provide a class method that sets the annual interest rate.





32



YourNameProg4.java class



In the YourNameProg4 Driver class, instantiate the saver1 and saver2 objects. Set the annual interest rate at 0.05. Print the table heading lines. Use a for loop to print the initial account numbers and balances and the account numbers and balances each month after that month’s interest has been added. After the last month’s printout, compute and display the total of both balances.

24



Your driver should generate the following outputs:







Output:



Monthly balances for one year with 0.05 annual interest:



Month Account # Balance Account # Balance

----- --------- ------- --------- -------

0 10002 2000.00 10003 3000.00

1 10002 2008.33 10003 3012.50

2 10002 2016.70 10003 3025.05

3 10002 2025.10 10003 3037.66

4 10002 2033.54 10003 3050.31

5 10002 2042.02 10003 3063.02

6 10002 2050.52 10003 3075.79

7 10002 2059.07 10003 3088.60

8 10002 2067.65 10003 3101.47

9 10002 2076.26 10003 3114.39

10 10002 2084.91 10003 3127.37

11 10002 2093.60 10003 3140.40

12 10002 2102.32 10003 3153.49



Final balance of both accounts combined: 5255.81



Explanation / Answer

please rate - thanks

import java.util.*;
public class SavingsAccountDriver
{public static void main(String[] args)
{SavingsAccount saver1 = new SavingsAccount(10002,2000);
SavingsAccount saver2 = new SavingsAccount(10003,3000);
saver1.annualInterestRate=.05;
int i;
System.out.println("Month Account #   Balance Account #   Balance");
System.out.println("----- ---------   ------- ---------   -------");
System.out.print("    0");
print(saver1);
print(saver2);
System.out.println();
for(i=1;i<=12;i++)
     {System.out.printf("%5d",i);
       printInt(saver1);
       printInt(saver2);
        System.out.println();
       }
System.out.printf("Final balance of both accounts combined: %.2f ",(saver1.getBalance()+saver2.getBalance()));

}
public static void printInt(SavingsAccount s)
{getInt(s);
print(s);
}
public static void print(SavingsAccount s)
{System.out.printf("%12d%10.2f ",s.getAccount_Number(),s.getBalance());
}
public static void getInt(SavingsAccount s)
{s.addMonthlyInterest();
}
}

---------------------------------

public class SavingsAccount
{public static double annualInterestRate;
private double balance;
private int ACCOUNT_NUMBER;
public SavingsAccount(int a,double b)
{
balance=b;
ACCOUNT_NUMBER=a;
}
public void addMonthlyInterest()
{
balance=balance+(balance * annualInterestRate / 12.);
}
public double getBalance()
{return balance;
}
public int getAccount_Number()
{return ACCOUNT_NUMBER;
}

}