113 Subclasses of Account In Programming Exercise 97 the Acc

11.3 (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 withdraw 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. Programming Exercise 11.3.

Use the following test program: public class Exercise11_03 { 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()); } }

Solution

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()

{

         

36

         return this.annualInterestRate;

37

}

public java.util.Date getDate()

{

return this.date;     

}

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;

}

   }

11.3 (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, b
11.3 (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, b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site