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

(Subclasses of Account) In Exercise 7.3, the Account class was created to model

ID: 3644658 • Letter: #

Question

(Subclasses of Account) In Exercise 7.3, the Account class was created to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw. 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. Implement the classes. Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount and invokes their toString ( ) methods.

Explanation / Answer

import javax.swing.JOptionPane; import java.util.Date; public class Account { private int id = 0; private double balance = 0; private double annualInterestRate = 0; private double withdraw = 0; private double deposite = 0; private double total = 0; private double monthly = 0; private Date date = new Date(); public Account() { } public Account(int id, double balance, double annualInterestRate){ this.id = id; this.balance = balance; this.annualInterestRate = annualInterestRate; } public int getId() { return this.id; } public double getBalance() { return this.balance; } public double getAnnualInterestRate() { return this.annualInterestRate; } public java.util.Date getDate() { return this.date; } public double getWithdraw() { return this.withdraw; } public double getDeposite() { return this.deposite; } public String toString() { return "Banking Account Information " + " Your Customer ID # " + id + " Starting Balnce $" + balance + " Annual Interest Rate " + annualInterestRate + "%" + " Withdraw Amount $" + withdraw + " Deposite Amount $" + deposite + " Subtotal $" + total + " Monthly Interest $" + Math.round(monthly * 100.0)/100.0 + " " + " " + "As of " + date; } }