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: 666023 • 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!!!

CHEEERS!!!


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 anInsufficientFundsException 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 0..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 Obiect model for a banking application

Explanation / Answer

Check this :

public class BankAccount {
    String firstName;
    String lastName;
    String ssn;
    protected float balance;
    float withdraw;
    float deposit;
    long accountNumber;

    BankAccount (){
    }

    BankAccount(String firstName, String lastName, String ssn, float balance){
        this.firstName = firstName;
        this.lastName = lastName;
        this.ssn = ssn;
        this.balance = balance;
    }

    long accountNumber() {
        long accountNumber = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
        return accountNumber;
    }

    public void deposit(float amount) {
    balance = balance + amount;
    System.out.println(firstName + " " + lastName + " deposited $" + deposit + ". Current Balance $" + balance);

    }   

    public void withdraw(float amount) {
        if (balance >= withdraw) {
            balance = balance - amount;
            System.out.println(firstName + " " + lastName + " withdrew $" + withdraw + ". Current Balance $" + balance);
        }
        if (balance < withdraw) {
            System.out.println("Unable to withdraw " + amount + " for " + firstName + " " + lastName + " due to insufficient funds.");
        }
    }
}
//Checking Account Subclass:

public class CheckingAccount extends BankAccount {

    float amtInterest;
    float applyInterest;
    String displayBalance;

    public CheckingAccount() {
    }

    public CheckingAccount(String firstName, String lastName, String ssn, float balance) {
        super(firstName, lastName, ssn, balance);
        System.out.println("Successfully created account for " + firstName + " " + lastName + " " + accountNumber);
        System.out.println(firstName + " " + lastName + ", Balance $" + balance);
    }   

    float applyInterest () {
       if (balance <= 10000) {
           balance = balance * 0.1f;
           }
       if (balance > 10000) {
           balance = 1000 + (balance * 0.02f);
       }
       return balance;
    }

    float displayBalance() {
        return balance;
    }
}
public class SavingsAccount extends BankAccount
   {
      public SavingsAccount(String string, double rate)
      {
      interestRate = rate;
      }
      public SavingsAccount(SavingsAccount yourAccount, int rate) {

      }
      public void addInterest()
      {
      double interest = getBalance() * interestRate / 100;
      deposit(interest);
      }
      private double interestRate;



      public void deposit(double amount) {}
      public boolean withdraw(double amount) {
      return false;}
      public void deductFees() {}
      private int transactionCount;



   public void postInterest() {
      double balance = getBalance();
      balance += (balance * interestRate);
      deposit(balance);

   }    
   }
  
  

public class BankApp {
    public static void main(String[] args) {
        CheckingAccount acct1 = new CheckingAccount("Alin", "Parker", "123-45-6789", 1000.0f);

        CheckingAccount acct2 = new CheckingAccount("Mary", "Jones", "987-65-4321", 500.0f);

        SavingsAccount acct3 = new SavingsAccount("John", "Smith", "1233-45-6789", 200.0f);

        acct1.deposit(22000.00f);
        acct2.deposit(12000.00f);


        acct1.withdraw(2000.00f);
        acct2.withdraw(1000.00f);

        acct1.applyInterest(); //seems to skip
        acct2.applyInterest(); //seems to skip

        acct1.displayBalance(); //seems to skip
        acct2.displayBalance(); //seems to skip

        acct1.withdraw(30000.00f);
    }
}

public void withdraw(double amount)

{

if (balance >= amount)

{

balance -= amount;

}

else

{

System.out.println("Insufficient funds");

}

also another approach :

public class BankAccount {
    String firstName;
    String lastName;
    String ssn;
    protected float balance;
    float withdraw;
    float deposit;
    long accountNumber;

    BankAccount (){
    }

    BankAccount(String firstName, String lastName, String ssn, float balance){
        this.firstName = firstName;
        this.lastName = lastName;
        this.ssn = ssn;
        this.balance = balance;
    }

    long accountNumber() {
        long accountNumber = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
        return accountNumber;
    }

    public void deposit(float amount) {
    balance = balance + amount;
    System.out.println(firstName + " " + lastName + " deposited $" + deposit + ". Current Balance $" + balance);

    }   

    public void withdraw(float amount) {
        if (balance >= withdraw) {
            balance = balance - amount;
            System.out.println(firstName + " " + lastName + " withdrew $" + withdraw + ". Current Balance $" + balance);
        }
        if (balance < withdraw) {
            System.out.println("Unable to withdraw " + amount + " for " + firstName + " " + lastName + " due to insufficient funds.");
        }
    }
}
//Checking Account Subclass:

public class CheckingAccount extends BankAccount {

    float amtInterest;
    float applyInterest;
    String displayBalance;

    public CheckingAccount() {
    }

    public CheckingAccount(String firstName, String lastName, String ssn, float balance) {
        super(firstName, lastName, ssn, balance);
        System.out.println("Successfully created account for " + firstName + " " + lastName + " " + accountNumber);
        System.out.println(firstName + " " + lastName + ", Balance $" + balance);
    }   

    float applyInterest () {
       if (balance <= 10000) {
           balance = balance * 0.1f;
           }
       if (balance > 10000) {
           balance = 1000 + (balance * 0.02f);
       }
       return balance;
    }

    float displayBalance() {
        return balance;
    }
}
public class SavingsAccount extends BankAccount
   {
      public SavingsAccount(String string, double rate)
      {
      interestRate = rate;
      }
      public SavingsAccount(SavingsAccount yourAccount, int rate) {

      }
      public void addInterest()
      {
      double interest = getBalance() * interestRate / 100;
      deposit(interest);
      }
      private double interestRate;



      public void deposit(double amount) {}
      public boolean withdraw(double amount) {
      return false;}
      public void deductFees() {}
      private int transactionCount;



   public void postInterest() {
      double balance = getBalance();
      balance += (balance * interestRate);
      deposit(balance);

   }    
   }
  
  

public class BankApp {
    public static void main(String[] args) {
        CheckingAccount acct1 = new CheckingAccount("Alin", "Parker", "123-45-6789", 1000.0f);

        CheckingAccount acct2 = new CheckingAccount("Mary", "Jones", "987-65-4321", 500.0f);

        SavingsAccount acct3 = new SavingsAccount("John", "Smith", "1233-45-6789", 200.0f);

        acct1.deposit(22000.00f);
        acct2.deposit(12000.00f);


        acct1.withdraw(2000.00f);
        acct2.withdraw(1000.00f);

        acct1.applyInterest(); //seems to skip
        acct2.applyInterest(); //seems to skip

        acct1.displayBalance(); //seems to skip
        acct2.displayBalance(); //seems to skip

        acct1.withdraw(30000.00f);
    }
}

public void withdraw(double amount)

{

if (balance >= amount)

{

balance -= amount;

}

else

{

System.out.println("Insufficient funds");

}

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