In: Computer Science
please, solve this problem.:
implementing with java language
create a bank account management system according to the following specifications:
BankAccount Abstract Class contains the following constructors and methods:
BankAccount(name, balance): a constructor that creates a new account with a name and starting balance.
getBalance(): a method that returns the balance of a specific account.
abstract deposit(amount): abstract method to be implemented in both Checking and SavingAccount classes.
abstract withdraw(amount): abstract method to be implemented in both Checking and SavingAccount classes.
messageTo Client (message): used to print a specific message to a client.
toString(): a method for printing accounts information.
CheckingAccount Class: A class that inherits from the Abstract Class BankAccount and implements both deposit () and withdraw ().
Deposit process in checking account has some constrains. Client can deposit any amount using checks and limit of $10,000.00 of cash deposit.
Client can withdraw any amount he wants.
SavingAccount Class: A class that inherits from the Abstract Class BankAccount and implements both deposit () and withdraw ().
A client can deposit any amount using checks and a limit of $5,000.00 of cash deposit. A 5% interest should be calculated on the total.
Client can only withdraw 20% of the total balance every 3 months.
Use interfaces for both checkingAccount and savingAccount classes.
BankAccountDriver class: this class is to test your code. The test should be done by creating an array of type BankAccount that stores different bank accounts types for different clients and perform some processing by calling the implemented methods on these accounts.
/*********************************BankAccount.java*********************************/
package bankaccount;
public abstract class BankAccount {
/*
* private data field
*/
private String name;
private double balance;
/**
*
* @param name
* @param balance
*/
public BankAccount(String name, double balance)
{
super();
this.name = name;
this.balance = balance;
}
// getter and setter for balance
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public abstract void deposit(double amount);
public abstract void withdraw(double amount);
public void messageToClient() {
}
@Override
public String toString() {
return "BankAccount [name=" + name
+ ", balance=" + balance + "]";
}
}
/****************************CheckingAccount.java****************************/
package bankaccount;
public class CheckingAccount extends BankAccount {
/**
*
* @param name
* @param balance
*/
public CheckingAccount(String name, double balance)
{
super(name, balance);
}
@Override
public void deposit(double amount) {
if (amount <= 10000) {
setBalance(getBalance() + amount);
}
else {
System.out.println("You can only deposit 1000");
}
}
@Override
public void withdraw(double amount) {
if (getBalance() > amount) {
setBalance(getBalance() - amount);
} else {
System.out.println("Insufficient funds!");
}
}
}
/******************************SavingAccount.java**************************/
package bankaccount;
public class SavingAccount extends BankAccount {
public SavingAccount(String name, double balance)
{
super(name, balance);
}
@Override
public void deposit(double amount) {
if (amount <= 5000) {
setBalance(getBalance() + amount);
double interest
= getBalance() * .05;
setBalance(getBalance() + interest);
} else {
System.out.println("Limit reached!");
}
}
@Override
public void withdraw(double amount) {
if (amount < getBalance() * .2) {
setBalance(getBalance() - amount);
} else {
System.out.println("You can't withdraw due to limit of saving
account!");
}
}
}
/******************************BankAccountDriver.java***************************/
package bankaccount;
public class BankAccountDriver {
public static void main(String[] args) {
BankAccount[] bankAccounts = new
BankAccount[3];
// fill array with different
accounts
bankAccounts[0] = new
CheckingAccount("Virat", 1000);
bankAccounts[1] = new
SavingAccount("Kohli", 2000);
bankAccounts[2] = new
CheckingAccount("MS", 3000);
// do some operation on all
account
for (BankAccount bankAccount :
bankAccounts) {
bankAccount.deposit(5000);
bankAccount.withdraw(1000);
}
// print information
for (BankAccount bankAccount :
bankAccounts) {
System.out.println(bankAccount.toString());
}
}
}
/***************************output*******************************/
BankAccount [name=Virat, balance=5000.0]
BankAccount [name=Kohli, balance=6350.0]
BankAccount [name=MS, balance=7000.0]
Please let me know if you have any doubt or modify the answer, Thanks :)