Question
IN JAVA PROGRAM In Exercise, The Account class was defined to model a bank account. An account has the properties account number, balance, annual interest
IN JAVA PROGRAM
In Exercise, 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 method to deposit and withdraw funds. Create two subclass 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 implement them. Write a test program that creates objects of Account, SavingAccount, and CheckingAccount and invokes their toString() methods.
Add a method named AccoundInf to implement the concept of polymorphism to display all the details of an account (This method can display the information of different types of Bank accounts). This method is not a class member method, it is outside the class.
This is how account class look like
public class Account { // instance variables private String accountNumber; private float balance; private float annualInterest; private Date createdDate; // Account constructor public Account(String accountNumber, float balance, float annualInterest) { this.accountNumber = accountNumber; this.balance = balance; this.annualInterest = annualInterest; this.createdDate = new Date(); } // function for deposit amount public void deposit(float amount){ if(amount>0) this.balance += amount; } // function for withdraw amount public void withdraw(float amount){ if(amount <= this.balance){ this.balance -= amount; } } // overriden to String @Override public String toString() { return "Account Details" + " Account Number: '" + accountNumber + '\'' + " Balance: " + balance + " Annual Interest: " + annualInterest + " Created Date: " + createdDate.toString(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started