Question: In Programming Exercise 9.7, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate,
In Programming Exercise 9.7, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and with- draw funds. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.
import java.util.Date;
import java.text.DecimalFormat;
public class Account {
DecimalFormat df=new DecimalFormat("#.##");
protected int id = 0;
protected double balance = 0;
protected double annualInterestRate = 0;
protected Date dateCreated;
public Account(){
}
public Account(int id, double balance, double annualInterestRate){
this.id = id;
this.balance = balance;
this. annualInterestRate = annualInterestRate;
}
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public double getBalance(){
return balance;
}
public void setBalance(double balance){
this.balance = balance;
}
public double getAnnualInterestRate(){
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate){
this.annualInterestRate = annualInterestRate;
}
public Date getDateCreated(){
dateCreated = new Date();
return dateCreated;
}
public double getMonthlyInterestRate(){
double annualInterest = annualInterestRate / 100;
return (annualInterest / 12);
}
public double getMonthlyInterest(){
return balance * getMonthlyInterestRate();
}
public void withdraw(double withdrawamount){
balance = balance - withdrawamount;
}
public void deposit(double amountdeposit){
balance = balance + amountdeposit;
}
public String toString() {
System.out.println("Acount ID: " + id);
System.out.println("Account Balance: $" + balance );
System.out.println("Monthly Interest: " + df.format(getMonthlyInterest()) + "%");
System.out.println("Date Opened: " + getDateCreated());
return "";
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
