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

Hullo! Please write the code for the following program using JAVA! Be sure to re

ID: 665973 • Letter: H

Question

Hullo! Please write the code for the following program using JAVA!

Be sure to read CAREFULLY before proceeding!!!

When done PLEASE compile and run to make sure the code WORKS!!!

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.

Explanation / Answer

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;
   }

}

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