Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Good Evening to all! I would like the Java code for the following programme (PLE

ID: 665391 • Letter: G

Question

Good Evening to all! I would like the Java code for the following programme (PLEASE keep in mind that Bank is a SINGLETON class, as well as transfers from the savings account!)

Implement the object model shown in Figure 1-25 to implement a small banking application. Create five classes: Bank, BankAccount,SavingsAccount, CheckingAccount, and Customer. Bank Should be a singleton class. For simplicity, the bank stores bank accounts in one array and customers in another. All bank accounts are savings accounts or checking accounts, and any customer may have zero or one account of each type.

The difference between the two accounts affects only the withdraw method. The deposit method simply increments the balance. The withdraw method decrements the balance, but cannot always do so. A customer can withdraw from a SavingsAccount only an amount less than or equal to the current balance. For a CheckingAccount the logic is:

Withdraw the amount if less than or equal to the balance.

If the customer has a SavingsAccount, and the SavingsAccount has enough money to cover the shortfall in the CheckingAccount, transfer enough money from saving to checking to cover the withdrawal. Then withdraw the money.

If the customer has no savings account, or the total of both accounts is less than the withdrawal amount, issue an InsufficientFundsException exception(just print message if Exception has not been covered).

Add a main method to the Bank class to test. Create one customer and give that customer a savings account. Try a deposit and withdrawal. Give the customer a checking account and try another deposit. Try withdrawals that succeed without a transfer, that transfer founds from savings, and for which there are insufficient funds.

Bank BankAccount accountNo owner balance accountList has O..n customerList addCustomer addAccount deposit abstract withdraw has SavingsAccount CheckingAccount withdravw withdravw 0..n Customer id savingsAcct checkingAcct 0..1 0..1 has addSavingsAccount addCheckingAccount Figure 1-25 Object model for a banking application

Explanation / Answer

Java code for Bank Application

import java.util.*;

import java.io.*;

import java.util.ArrayList;

abstract class BankAccount//Class declaration

{

int account_No;

String account_name;

double accnt_balance;  

public BankAccount(int account_Num 1, String account_nam1,double accnt_balance1)

{

this.account_No = account_Num 1;

this.account_name = account_nam1;

this.accnt_balance=accnt_balance1;

}

public int getAccnt_id()

{

return account_No;

}

public String getAccount_Name()

{

return account_name;

}

public void deposit(int m_amt)

{

accnt_balance= accnt_balancee+m_amt;

System.out.println("Money in Account deposited with $"+m_amt);

}

public abstract void withdraw(int m_amt);

}

/Created a CLASS for SavingsAccount/

class SavingsAccount extends BankAccount

{

public SavingsAccount(int account_Num 1, String account_nam1, double accnt_balance1)

{

super(account_Num 1, account_nam1, accnt_balance1);

}

public void withdraw(int m_amt)

{

if(a_amt<=accnt_balance)

{

accnt_balance=accnt_balance-m_amt;

System.out.println("SUCESSFULLY WITHDRAWN!");

}

else

System.out.println("INSUFFICIENT BALANCE");

}  

public void display()

{

System.out.println("Balance is $"+accnt_balance);

}

}

/Created a CLASS for CheckingAccount/

class CheckingAccount extends BankAccount

{

Customer m_cust;

public CheckingAccount(int account_No, String account_name,double accnt_balance)

{

super(account_No, account_name, accnt_balance);  

}

public void withdraw(int m_amt)

{

if(a_amt<=accnt_balance)

{

accnt_balance=accnt_balance-m_amt;

System.out.println("SUCESSFULLY WITHDRAWN!!");

}

else

{

boolean flag12=m_cust.transferMoney(this,m_amt);

if(!flag12)

System.out.println("INSUFFICIENT BALANCE");

}

}  

public void display()

{

System.out.println("ACCOUNT BALANCE is $"+accnt_balance);

}

}

/Created a CLASS for Customer/

class Customer

{

int cust_id;

String cust_name;  

ArrayList<SavingsAccount> savingAccnt=new ArrayList<SavingsAccount>();

ArrayList<CheckingAccount> checkingAcct=new ArrayList<CheclingAccount>();

  

  

public Customer(int m_id, String m_name)

{

this.cust_id = m_id;

this.cust_name = m_name;

}

//ADDING a new CheckingAccount

public void addCheckingAccount(CheckingAccount chk_accnt)

{

checkingAcct.add(chk_accnt);

}

//ADDING new SavingAccount

public void adddSavingAccount(SavingAccount sav_accnt)

{

savingAccnt.add(sav_accnt);

}

public boolean transferMoney(CheckingAccount chk_accnt,int a_amt)

{

boolean isMoneyTransfer=false;

for(int i=0;i<m_saving;i++)

{

if(savingAccnt.get(i).getAccnt_id()==chk_accnt.getAccnt_id())

{

m.saving.get(i).withdraw(m_amt);

isMoneyTransfer=true;

}

}

return isMoneyTransfer;

}  

}

//Created CLASS name for Bank

class Bank

{

private ArrayList<BankAccount> bankaccountList=new ArrayList<BankAccount>();

private ArrayList<Customer> cust_customerList=new ArrayList<Customer>();

//ADDS NEW Customer

public void addCustomer(Customer newcust12)

{

cust_customerList.add(newcust12);

}

//ADDS NEW BankAccount

public void addAccount(BankAccount newacc12)

{

bankaccountList.add(newacc12);

}

}

// CLASS BankImplementation

public class BankImplementation

{

public static void main(String[] args)

{

int m_id=110;

String m_name="Client";

double m_bal=1000;

SavingsAccount newsaving=new SavingsAccount(m_id, m_name, m_bal);

Customer newCust301=new Customer(m_id, m_name);

newCust301.addSavingAccount(newsaving);

CheckingAccount newCheckingAccount=new CheckingAccount(m_id,m_name,1000);

newCust301.addCheckingAccount(newCheckingAccount);

newCust301.newsaving.display();

newCust301.newsaving.withdraw(1000);

newCust301.newsaving.display();

newCust301.newCheckingAccount.display();

newCust301.newCheckingAccount.withdraw(2000);

newCust301.newCheckingAccount.display();  

}//end the main program

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote