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

I have this Java Project and it is only done, but I have a few problems. First h

ID: 665561 • Letter: I

Question

I have this Java Project and it is only done, but I have a few problems. First here is the assignment:

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. Thedeposit method simply increments the balance. The withdraw method decrements the balance, but cannot always do so. A customer can withdraw from aSavingsAccount only an amount less than or equal to the current balance. For aCheckingAccount 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).

Here is my code:

Bank.java

public class Bank

{
   private ArrayList<BankAccount> accountList=new ArrayList<BankAccount>();
   private ArrayList<Customer> customerList=new ArrayList<Customer>();
  
   public void addCustomer(Customer cus)
   {
       customerList.add(cus);
   }
   public void addAccount(BankAccount acc)
   {
       accountList.add(acc);
   }

   public static void main(String[] args)
   {
       SavingsAccount savings = new SavingsAccount(1, "Bob", 2000);
       CheckingAccount checking = new CheckingAccount(1, "Bob", 2000);   
       Customer customer1 = new Customer(1, savings);
       Customer customer2 = new Customer(1, checking);
      
       Bank newcust = new Bank();
       newcust.addCustomer(customer1);
       newcust.addCustomer(customer2);
       customer1.addSavingsAccount().withdraw(1000);
   customer1.addSavingsAccount().displayAmount();
   customer1.addSavingsAccount().deposit(500);
   customer1.addSavingsAccount().displayAmount();
   customer1.addSavingsAccount().withdraw(1000);
   customer1.addSavingsAccount().displayAmount();
  
   customer2.addCheckingAccount().withdraw(1000);
   customer2.addCheckingAccount().displayAmount();
   customer2.addCheckingAccount().deposit(1000);
   customer2.addCheckingAccount().displayAmount();
   customer2.addCheckingAccount().withdraw(1000);

BankAccount.java

public abstract class BankAccount
{
       private int accountNo;
       private String owner;
       double balance;
      
       public BankAccount(int accountnum, String own, double bal)
       {
           accountNo = accountnum;
           owner = own;
           balance = bal;
          
       }
       public void deposit(int a)
       {
           balance = a + balance;
       }
       public abstract void withdraw(int a);
}
  
  
  
  
   }
}

CheckingAccount.java

public class CheckingAccount extends BankAccount
{
   public CheckingAccount(int accountNo, String owner, double balance)
   {
       super(accountNo, owner, balance);
      
   }
   public void withdraw(int a, SavingsAccount f)
   {
       if(a <= balance)
       {
           balance = balance - a;
       }
       else if(a >= balance && f.equals(true) && f.balance >= balance - a )
       {
           balance = 0;
           f.balance = f.balance + (balance - a);
       }
       else
           System.out.println("InsufficientFundsException" );
      
   }
   public void displayAmount()
   {
       System.out.println("The checking balance is: " + balance);
   }
   @Override
   public void withdraw(int a) {
      
      
   }

  
}

SavingsAccount.java

public class SavingsAccount extends BankAccount
{
   public SavingsAccount(int accountNo, String owner, double balance)
   {
   super(accountNo, owner, balance);
  
   }

   public void withdraw(int a)
   {
   if(a<=balance)
   {
   balance=balance-a;
     
   }
   else
   System.out.println("InsufficientFundException");
   }
  
   public void displayAmount()
   {
   System.out.println("The savings balance is: "+balance);
   }
}

Customer.java

public class Customer
{
   private int id;
   private SavingsAccount savingsAcct;
   private CheckingAccount checkingAcct;
  
   public Customer(int i, SavingsAccount savingsAcc)
   {
       id = i;
       savingsAcct = savingsAcc;
      
   }
   public Customer(int i, CheckingAccount checkingAcc)
   {
       id = i;
       checkingAcct = checkingAcc;
   }
   public void setSavingAccount(SavingsAccount saving)
   {
       savingsAcct = saving;
  
   }

   public void setCheckingAccount(CheckingAccount checking)
   {
   checkingAcct = checking;
   }
  
   public SavingsAccount addSavingsAccount()
   {
       return savingsAcct;
   }
   public CheckingAccount addCheckingAccount()
   {
       return checkingAcct;
   }

}

My problem, is that my Bank class is not singleton and I can't seem to make a customer have both a checking and savings account. I just need to fix my program to fit the criteria of the instructions. Please do not just correct small mistakes in my code, what I need help with is how to make my Bank class a singleton class, and fit the requirement of the assignment.

Bank BankAccount accountNo owner balance accountList has 0..n customerList addCustomer addAccount deposit abstract withdraw has SavingsAccount CheckingAccount withdravw withdravw 0..n Customer id savingsAcct checkingAcct 0..1 0..1 has 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

}