Create two subclasses of the Account class, one for checking accounts, Checking, and one for saving accounts, Saving. These two subclasses cannot be extended any further. A checking account has overdraft limit, but a saving account doesn’t have an overdraft. A Saving account is an interest-bearing financial product, but checking accounts are not.
Overdraft in a bank account means the balance can go for negative value, say -$500.00.
Interest-bearing bank account means the bank pays an interest, with a pre-specified rate, for positive balances in the account, calculated daily, paid monthly, for typical bank accounts. For simplicity, we will consider only fixed, non-cumulative rate calculations. For instance if the balance is $1000, annual rate is 3%, then the total interest would be (3/100 * 1000 = $30 per annum, or $30/12 months = $2.5 monthly.
Hints. To develop a nice, and easy to implement solution, try to write the above paragraph as functional and non-functional requirements. For example
Functional Requirements: Two types of accounts, checking and saving.
Non-Functional Requirements: as design constraint, e.g. these two accounts cannot be further extended.
After splitting each description of the project, most often, but not always, is to design and implement the functional objectives of the project (i.e. the functional requirements in this exercise). After this, implement the non-functional requirements, as additional constraints.
when Account class :
import java.util.Date;
public class Account {
int id ;
String name;
double balance;
double annualInterestRate ;
Date dateCreated ;
public Account()
{
dateCreated = new Date();
};
public Account(int id , String name)
{
dateCreated = new Date();
this.id=id;
this.name=name;
};
public Account(int id , String name , double balance )
{
dateCreated = new Date();
this.id=id;
this.name=name;
this.balance=balance;
};
public Account(int id, String name, double balance, double annualInterestRate)
{
dateCreated=new Date();
this.id=id;
this.name=name;
this.balance=balance;
this.annualInterestRate=annualInterestRate;
}
public void setID(int id1)
{
id=id1 ;
}
public int getID()
{
return id;
}
public void setANNUAL(double annual)
{
annualInterestRate=annual;
}
public double getANNUAL()
{
return annualInterestRate;
}
public void setNAME(String name1)
{
name=name1;
}
public String getNAME()
{
return name;
}
public void setBALANCE(double balance1)
{
balance = balance1;
}
public double getBALANCE()
{
return balance;
}
double getMonthlyInterestRate()
{
return balance/12;
}
public double withdraw(double amount )
{
balance = this.balance - amount ;
return balance ;
}
public double deposit(double amount )
{
balance = this.balance + amount ;
return balance ;
}
public boolean equals(Object other){
if (other instanceof Account){
if(other==null && this == null)
return true;
else
{
Account obj=(Account) other;
if(obj.id==this.id && obj.name==this.name)
return true;
else{
return false;
}
}
}
else return false;
}
public String toString(){
return "Name : " + this.name +
"\n" +"ID : " + this.id +
"\n" +"Balance :" + this.balance +
"\n" +"DateCreated :" +this.dateCreated +
"\n" +"MonthlyInterestRate :" +this.getMonthlyInterestRate() ;
}
}
and the Test Class :
public class TestAccount {
public static void main(String[] args) {
Account account1 = new Account(740135 ,"Alma Mather" , 500 ) ;
Account account2 = new Account(32842 ,"Harley Hacker" ,4000 ) ;
Account account3 = new Account(224519 ,"Carl Cracker," , 1000 ) ;
// ACCOUNT 1
account1.deposit(100);
account1.withdraw(200);
account1.withdraw(100);
account1.withdraw(50);
account1.deposit(150);
// ACCOUNT 2
account2.withdraw(700);
account2.withdraw(400);
account2.deposit(300);
account2.withdraw(40);
account2.withdraw(200);
// ACCOUNT 3
account3.withdraw(300);
account3.withdraw(100);
account3.deposit(250);
account3.withdraw(40);
account3.withdraw(200);
/////
System.out.println(account1.toString());
System.out.println();
System.out.println();
System.out.println(account2.toString());
System.out.println();
System.out.println();
System.out.println(account3.toString());
System.out.println();
System.out.println();
}
}