Java inheritance exercise Pursose: This exercise allows you to implement inherit
ID: 3819938 • Letter: J
Question
Java inheritance exercise Pursose: This exercise allows you to implement inheritance and polymorphism. Description Write a bank a Bank Account project according to the following specifications: Bank Account: Every bank account has an identifier, a PIN, and a balance. Every bank account should have a way to deposit an amount, withdraw an amount(abstract method), and display the current balance. Ensure that any class that inherits from this class has a withdraw() method that overrides the abstract withdraw() method. Savings: The withdraw method will only let the owner withdraw if the funds are sufficient. If the owner attempts to withdraw an amount higher than the balance, print an error message and do not process the withdraw. Checking: The withdraw method should withdraw the amount only if the funds are availible, and apply a service fee of $0.25 for each withdrawal to the balance. If the owner. if the owner attempts to withdraw more than the balance of the account, print an error message and do not process the withdraw. CheckingPlus: The withdraw method will allow the owner to withdraw more than the balance up to a predefined limite(the limit is a field in the class, the numer I used was 1000) If the amount requested is approved the fee is applied. The fee is a percentage of the amount overdrawn(ex: 10%). If the limit is exceeded, throw and catch the error. Testing: In main() create an array of five BankAccounts objects and each account will have a unique ID. Then allow the user to enter the BankAccount ID and PIN to either deposit or withdraw an amount. After each transaction, display the current balance. if the account ID with the PIN number is wrong, print an error message to the user and ask for another ID and PIN.
Explanation / Answer
import java.util.Date;
import java.*;
public class Bank
{
private int id = 0;
private double bal= 0;
private static double yearInterestRate = 0;
private Date dateCreated = new Date();
Bank()
{
id = 0;
bal = 0.0;
yearInterestRate = 0.0;
}
public Bank(int newId, double newBal)
{
id = newId;
bal = newBal;
}
Bank(int newId, double newBal, double newyearInterestRate)
{
id = newId;
bal = newBal;
yearInterestRate = newyearInterestRate;
}
public int getId()
{
return id;
}
public double getBal()
{
return bal;
}
public double getyearInterestRate()
{
return yearInterestRate;
public void setId(int newId)
{
id = newId;
public void setBal(double newBalance)
{
bal = newBal;
}
public static void setyearInterestRate(double newyearInterestRate)
{
yearInterestRate = newyearInterestRate;
}
public Date getDateCreated()
{
return dateCreated;
}
double getMonthlyInterestRate()
{
return yearInterestRate/12/100 * bal;
}
double withdraw(double amount)
{
return balance -= amount;
}
double deposit(double amount)
{
return balance += amount;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.