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

[Java] Please fix my code. Please modify the class named SavingAccount only, not

ID: 3573291 • Letter: #

Question

[Java] Please fix my code.

Please modify the class named SavingAccount only, nothing else.

SavingsAccount:

This is a subclass of BankAccount. The owner of the account can deposit or withdraw money at any point. The account earns 0.9% interest annually compounded monthly. Interest is paid on the ending balance during end of month processing. Use a constant for annual interest rate.

Write an application called AccountRunner. (It will have a main method) Do the following.

Create a BankAccount array that can hold 3 item. Add these items

at index 0, add a BankAccount with an initial balance of 1000 and an id of B2222

at index 1, add a FeeBasedAccount with an initial balance of 1000 and an id of F3333

At index 2, add a SavingsAccount with an initial balance of 1000 and an id of S4444

Loop through the array:

call the deposit method on each account with an amount of 250.

call the deposit method on each account again and add 50

call the withdraw method on each account with an amount of 100

Now from only the FeeBasedAccount, withdraw another 100

Finally in a second loop

call endOfMonth() on each account

print the account id and the balance to 2 decimal places of each account, each on a separate line

Use the following files:

BankAccount.java

FeeBasedAccount.java

AccountRunner.java

/**
* Tester for BankAccount and its subclasses
*/
public class AccountRunner
{
public static void main(String[] args)
{
BankAccount account = new SavingsAccount(1000, "abc123");
account.endOfMonth();

  
System.out.printf("after one month: %.2f%n" , account.getBalance());
System.out.println("Expected: 1000.75");

account = new SavingsAccount(1000, "qrs123");
account.withdraw(100);
  
//do a 12 end of month processings
for(int i = 0; i < 12; i++)
{
account.endOfMonth();
}
account.deposit(100);
  
System.out.printf("%.2f%n" , account.getBalance());
System.out.println("Expected: 1008.13");
  

}
}

Complete the following files:

SavingsAccount.java

public class SavingAccount extends BankAccount
{
public double AccountRunner()
{
BankAccount[] acc = new BankAccount[3];
acc[0]=accounts;
acc[1]=account1;
acc[2]=account2;

for (BankAccount a: acc)
{
a.deposit(250);
a.deposit(50);
a.withdraw(100);
}

account1.withdraw(100);

//do a 12 end of month processings
for(int i = 0; i < 12; i++)
{
acc[0].endOfMonth();
acc[1].endOfMonth();
acc[2].endOfMonth();
}

System.out.printf("B2222 %.2f%n" , accounts.getBalance());
System.out.printf("F3333 %.2f%n" , account1.getBalance());
System.out.printf("S4444 %.2f%n" , account2.getBalance());
}
}

Explanation / Answer

Below is the modified SavingsAccount.java

public class SavingsAccount extends BankAccount
{
   double initialBalance;
   String id ;
public SavingsAccount(double initialBalance, String id) {
       super(initialBalance, id);
       this.initialBalance= initialBalance;
       this.id= id;
   }

   public void AccountRunner()
{
BankAccount[] acc = new BankAccount[3];
BankAccount accounts = new BankAccount(5000, "abc");
BankAccount account1 = new BankAccount(5000, "abc1");
BankAccount account2 = new BankAccount(5000, "abc2");
  
acc[0]=accounts;
acc[1]=account1;
acc[2]=account2;
for (BankAccount a: acc)
{
a.deposit(250);
a.deposit(50);
a.withdraw(100);
}
account1.withdraw(100);
//do a 12 end of month processings
for(int i = 0; i < 12; i++)
{
acc[0].endOfMonth();
acc[1].endOfMonth();
acc[2].endOfMonth();
}
System.out.printf("B2222 %.2f%n" , accounts.getBalance());
System.out.printf("F3333 %.2f%n" , account1.getBalance());
System.out.printf("S4444 %.2f%n" , account2.getBalance());
}
}

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