The only differences between SavingsAccount and BankAccount objects is that Savi
ID: 3553802 • Letter: T
Question
The only differences between SavingsAccount and BankAccount objects is that SavingsAccount have an interest rate and can compute interest when necessary. Add an instance variable and a method to SavingsAccount to allow for these items.
Now create a tester class to demonstrate that you can:
* Create a SavingsAccount object
* Withdraw from the SavingsAccount
* Deposit to the SavingsAccount
* Compute interest against the balance in the SavingsAccount
* Display the balance of the SavingsAccount
For full credit your SavingsAccount class MUST extend your BankAccount class. Additionally, no methods should be overridden.
Your Netbeans project will contain 3 classes: BankAccountTester (or whatever you choose to name it), BankAccount and SavingsAccount.
Please and Thank you
Explanation / Answer
( Done EXACTLY following mentioned Specifications )
Indented Code link : http://ideone.com/jlQLQD
import java.util.*;
class BankAccountTester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
SavingsAccount account = new SavingsAccount("James Howard",12345678);
System.out.println("This is working fine!");
// Add further operations here
}
public static class BankAccount
{
boolean status;
private String accountName;
private int accountNum, numDeposits, numWithdrawals;
private double balance, annualInterest, monthlyCharges;
public BankAccount(String name, int num)
{
accountName = name;
accountNum = num;
}
public void Deposit(double d)
{
balance=balance+d;
numDeposits++;
}
public void withdraw(double w)
{
balance=balance-w;
numWithdrawals++;
if(balance<25) status=false;
}
}
public static class SavingsAccount extends BankAccount
{
public SavingsAccount(String name, int num)
{
super(name, num);
}
public void calcInterest()
{
double mir=(super.annualInterest/12);
double mi=super.balance*mir;
super.balance=super.balance*mi;
}
public void Withdraw(double w)
{
if(super.status) super.withdraw(w);
else System.out.println("The account balance is less than $25, cannot withdraw!!");
}
public void Deposit(double d)
{
super.Deposit(d);
if(super.balance>25) super.status = true;
else
{
super.status = false;
System.out.println("You have to enter more to make account active!!");
}
}
}
}