Question0133593517.pdf(Subclasses of Account) 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
...[Show More]
Question
0133593517.pdf
- (Subclasses of Account) 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. Draw the UML diagram for the classes and then implement them. Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount and invokes their toString() methods.
- This is my code from Exercise 9.7:
public class Exercise09_07 {
public static void main (String[] args) {
Account account = new Account(1122, 20000);
account.setAnnualInterestRate(4.5);
account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());
}
}
class Account {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
Account()
{
this.id = 0;
this.balance = 0;
this.annualInterestRate = 0;
this.dateCreated = new java.util.Date();
}
public Account(int id, double balance) {
super();
this.id = id;
this.balance = balance;
this.dateCreated = new java.util.Date();
}
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/100;
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate()
{
return this.annualInterestRate / 12;
}
public double getMonthlyInterest(){
return getMonthlyInterestRate()*this.balance;
}
public void withdraw(double amount)
{
this.balance = this.balance - amount;
}
public void deposit(double amount)
{
this.balance = this.balance + amount;
}
public static void main(String[] args) {
CheckingAccount checking = new CheckingAccount(1, 35);
SavingsAccount savings = new SavingsAccount(2, 25);
checking.withdraw(10);
savings.withdraw(10);
System.out.println(checking.getBalance());
System.out.println(savings.getBalance());
}
}
-
[Show Less]