Use the Account class that you created in your previous assignment to model a Ba
ID: 3544423 • Letter: U
Question
Use the Account class that you created in your previous assignment to model a Bank account. Create two subclasses for Checking and Savings account that extend your Account class from previous assignment. Implement the following in these 2 subclasses:
? A Checking account has an overdraft limit (of $5,000), but a Savings account cannot
be overdrawn. Override the withdraw method in these subclasses to take care of the
overdraft restrictions.
? All data and methods are inherited from Account class.
? Create constructors for both Checking and Savings account. These constructors
should invoke the constructors of their superclass
Change the deposit method in Account class. Create two overloaded deposit methods in Account class such that one of them takes an integer value as the input parameter and the second one takes a double value as the input parameter.
Write a test program (class named TestAccount) that does the following:
a) Creates 2 objects - a Saving Account and a Checking Account. Get user inputs for
account information that is needed to create these 2 objects.
b) Get user input for an amount to be withdrawn from the Checking Account (for
example, $2,500) and an amount to be deposited to the Checking Account (for
example, $3,000). Make sure the overdraft restrictions work.
c) Similarly, withdraw and deposit from and into the Saving Account also.
d) Finally, print the account information for both the Checking and Saving accounts
(i.e., print the current balance (after withdrawal and deposit), the monthly interest, and the date when these two accounts were created).
Recap of Account class:
Account class has the following data and behavior
? An integer data field
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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.