Use the following files BankAccountjava FeeBasedAccountjava
Use the following files:
BankAccount.java
FeeBasedAccount.java
Complete this AccountRunner.java file:
/**
* 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\");
}
}
Code SavingsAccount.java:
In this problem you are dealing with a hierarchy of inheritance. You will use the BankAccount and FeeBasedAccount from 12b along with the SavingsAccount class you will write 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 FeeBased.Account 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 arra 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 FeeBased Account, withdraw another 100 Finally in a second loop call endo fMonth0 on each account print the account id and the balance to 2 decimal places of each account, each on a separate lineSolution
/**
*FileName:SavingsAccount.java
*/
public class SavingsAccount extends BankAccount {
public static final double anualInterestRate = 0.9;
/**
* This is constructor for initialization
* @param initialBalance
* @param id
*/
public SavingsAccount(int initialBalance, String id) {
super((double) initialBalance, id);
}
@Override
public void withdraw(double amount) {
super.withdraw(amount);
}
@Override
public void deposit(double amount) {
super.deposit(amount);
}
@Override
public void endOfMonth() {
super.endOfMonth();
super.deposit(compoundInterest(super.getBalance()));
}
/**
*
* @param amount
* @return
*/
public double compoundInterest(double amount){
double compoundAmount = (amount*anualInterestRate)/(12*100);
return compoundAmount-amount;
}
}
/**
*FileName:AccountRunner.java
*/1290
public class AccountRunner {
public static void main(String[] args) {
BankAccount [] account= new BankAccount[3];
account[0] = new BankAccount(1000, \"B2222\");
account[1] = new FeeBasedAccount(1000, \"F3333\");
account[2] = new SavingsAccount(1000, \"S4444\");
for(int i=0;i<3;i++){
account[i].deposit(250);
account[i].deposit(50);
account[i].withdraw(100);
}
account[1].withdraw(100);
for(int i=0;i<3;i++){
account[i].endOfMonth();
}
for(int i=0;i<3;i++){
System.out.printf(\"Account ID: %s\", account[i].getAccountId());
System.out.printf(\"balance: %.2f%n\", account[i].getBalance());
}
}
}


