Write a Java program for the following This banking system i

Write a Java program for the following:

This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (which will contain the main method), Account, CheckingAccount, SavingsAccount and Balance. Both the CheckingAccount and SavingsAccount classes will inherit from class Account, and they will both have a data member of type Balance. Within method main, which is within class MustangBanking, create an ArrayList of type Account. You may call this ArrayList accounts. Within a loop, display the messages “Welcome to your Mustang Bank!” and “Please choose from the following options:”. These options will be:

1 – Create a new Checking Account

2 – Create a new Savings Account

3 – Delete an existing account

4 – View a specific account

5 – View all accounts

6 – Write a check through a specific Checking Account

7 – Withdraw funds from a specific account

8 – Deposit funds into an account

9 – Exit Program

Please enter your option below:

For option 1, call the method xCreateChecking, sending accounts. Upon returning, print out a statement that the Checking Account has been created. For option 2, call the method xCreteSavings, sending accounts. Upon returning, print out a statement that the Savings Account has been created. For option 3, call the method xDeleteAccount, sending accounts. For option 4, call the method xViewSpecific, sending accounts. For option 5, call the method xViewAll, sending accounts. For option 6, call the method xWriteCheck, sending accounts. For option 7, call the method xWithdraw, sending accounts. For option 8, call the method xDeposit, sending accounts. Option 9 should have the loop end and the program exit. Classes: The Account class will consist of: iId (integer) dInterestRate (double) bBalance (Balance) – Balance is a separate class With methods: Constructor Account, which takes in the Id, Interest Rate and Balance amounts. getId setId getInterestRate setInterestRate deposit - which takes in an amount and adds that to the current balance withdraw – takes in an amount and subtracts it from the current balance NOTE: If funds do not exist for the withdraw, a message must be displayed that funds are not available. displayAccount – Displays a message showing the account Id, Balance and Interest Rate The CheckingAccount class extends, or inherits from class Account. In addition, It has: Constructor CheckingAccount that takes in the ID, Balance and Interest Rate (recall, it must then call the super class with the command super() sending it the amounts as well) It also has the methods: xWriteCheck – which accepts the account ID It will first loop through the accounts to determin if the given account exists If so, will prompt the user for the check amount and will withdraw the check amount from the account If the account DOES NOT exist, a message must be displayed indicating the given ID does not exist. The SavingsAccount class extends the Account class as well. In addition, it has: Constructor SavingsAccount – Takes in the ID, Balance and Interest Rate (It too must then call the super class) Withdraw – which takes in an amount to withdraw If funds are available, the received amount is subtracted from the Balance Otherwise, a message is displayed indicating funds are not available. The Balance class will consist of: dBalance (double) with methods: Constructor Balance – Have a default constructor which sets the dBalance to 0.0 And a second constructor Balance which takes in an amount that Balance is set to. getBalance setBalance PLEASE NOTE: During some of the method processing, you will want to be sure the account you are checking is either a savings or checking account. This can be done with the ‘instanceof’ operator. For example: If (accounts.get(i) instanceof SavingsAccount) { //-- this is a savings account }

Solution

public class Account {

   private double balance;
   protected int accno;

   public int getAccno() {
       return accno;
   }

   public void setAccno(int accno) {
       this.accno = accno;
   }

   public double getBalance() {
       return balance;
   }

   public void setBalance(double balance) {
       this.balance = balance;
   }

   public Account(double balance, int accno) {
       this.balance = balance;
       this.accno = accno;
   }

   @Override
   public String toString() {
       return \"Account [balance=\" + balance + \", accno=\" + accno + \"]\";
   }

   public double withdraw(double amount) {

       return balance - amount;

   }

   public double deposit(double amount) {
       return balance + amount;
   }

}

public class CheckingAccount extends Account {

   public CheckingAccount(double balance, int accno) {
       super(balance, accno);
   }

   @Override
   public String toString() {
       return \"CheckingAccount getAccno()=\" + getAccno() + \", getBalance()=\"
               + getBalance();

   }

}

public class SavingsAccount extends Account {

   public SavingsAccount(double balance, int accno) {
       super(balance, accno);
   }

   @Override
   public String toString() {
       return \"SavingsAccount [getAccno()=\" + getAccno() + \", getBalance()=\"
               + getBalance() + \"]\";
   }

}

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class MustangBanking {

   private static List<Account> list = new ArrayList<Account>();

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       int i = 1;
       while (i == 1) {
           System.out.println(\"welcome to the mustang bank\");
           System.out.println(\"please choose the following opnions\");
           System.out.println(\"1 – Create a new Checking Account\");
           System.out.println(\"2 – Create a new Savings Account\");
           System.out.println(\"3 – Delete an existing account\");
           System.out.println(\"4 – View a specific account\");
           System.out.println(\"5 – View all accounts\");
           System.out
                   .println(\"6 – Write a check through a specific Checking Account\");
           System.out.println(\"7 – Withdraw funds from a specific account\");
           System.out.println(\"8 – Deposit funds into an account\");
           System.out.println(\"9 – Exit Program\");
           System.out.println(\"enter your choice\");
           int choice = scanner.nextInt();
           switch (choice) {
           case 1:
               System.out
                       .println(\"please deposit initial balance to deposit to create cheking account\");
               double amount = scanner.nextDouble();
               Random rand = new Random();
               int accno = rand.nextInt(1000);

               Account account = new CheckingAccount(amount, accno);
               System.out.println(\"checking account created\");
               list.add(account);
               break;
           case 2:
               System.out
                       .println(\"please deposit initial balance to deposit to create savings account\");
               double amount1 = scanner.nextDouble();
               Random random = new Random();
               int accno1 = random.nextInt(1000);
               Account account1 = new SavingsAccount(amount1, accno1);
               list.add(account1);
               System.out.println(\"savings account created\");
               break;
           case 3:
               System.out
                       .println(\"enter accno to remove the account in the bank\");
               int removeaccno = scanner.nextInt();
               int count = 0;
               for (Account accs : list) {
                   if (removeaccno == accs.getAccno())
                       ;
                   {
                       list.remove(accs);
                       count++;
                   }

               }
               System.out.println(\"\");
               if (count == 0) {
                   System.out.println(\"record not found to delete\");
               }
               break;

           case 5:
               System.out.println(\"to view all accounts\");
               for (Account accoutn : list) {
                   System.out.println(accoutn);
               }
               break;

           case 4:
               System.out.println(\"enter the accno to view specific account\");
               int accountno = scanner.nextInt();
               int count1 = 0;
               for (Account accs : list) {
                   if (accountno == accs.getAccno()) {
                       System.out.println(accs);
                       count1++;
                   }
               }
               if (count1 == 0) {
                   System.out.println(\"account not found\");
               }
               break;
           case 6:
               System.out.println(\"writing check\");
               System.out.println(\"enter account no\");
               int accountnumber = scanner.nextInt();
               System.out.println(\"enter the amount in the check\");
               double checkAmount = scanner.nextDouble();
               for (Account accs : list) {
                   if (accountnumber == accs.getAccno()) {
                       accs.withdraw(checkAmount);
                   }
               }
               System.out.println(\"the check withdraw amount is \"
                       + checkAmount);
               break;
           case 7:
               int accountnumber1 = scanner.nextInt();
               System.out.println(\"enter the amount to withdraw\");
               double checkAmount1 = scanner.nextDouble();
               for (Account accs : list) {
                   if (accountnumber1 == accs.getAccno()) {
                       accs.withdraw(checkAmount1);
                   }
               }
               System.out.println(\"the withdraw amount is \" + checkAmount1);
               break;

           case 8:
               System.out.println(\"enter account no to deposit\");
               int accountnumber2 = scanner.nextInt();
               System.out.println(\"enter the amount in the check\");
               double checkAmount2 = scanner.nextDouble();
               for (Account accs : list) {
                   if (accountnumber2 == accs.getAccno()) {
                       accs.withdraw(checkAmount2);
                   }
               }
               System.out.println(\"the check withdraw amount is \"
                       + checkAmount2);
               break;
           case 9:
               System.out.println(\"do you want to exit or not type y/n\");
               String exitChoice = scanner.next();
               if (\"y\".equals(exitChoice)) {
                   System.exit(0);
               } else
                   break;
           default:
               System.out.println(\"you choosen wrong choice\");
               break;

           }

       }
   }
}

output

welcome to the mustang bank
please choose the following opnions
1 – Create a new Checking Account
2 – Create a new Savings Account
3 – Delete an existing account
4 – View a specific account
5 – View all accounts
6 – Write a check through a specific Checking Account
7 – Withdraw funds from a specific account
8 – Deposit funds into an account
9 – Exit Program
enter your choice
1
please deposit initial balance to deposit to create cheking account
1500
checking account created
welcome to the mustang bank
please choose the following opnions
1 – Create a new Checking Account
2 – Create a new Savings Account
3 – Delete an existing account
4 – View a specific account
5 – View all accounts
6 – Write a check through a specific Checking Account
7 – Withdraw funds from a specific account
8 – Deposit funds into an account
9 – Exit Program
enter your choice
2
please deposit initial balance to deposit to create savings account
2564
savings account created
welcome to the mustang bank
please choose the following opnions
1 – Create a new Checking Account
2 – Create a new Savings Account
3 – Delete an existing account
4 – View a specific account
5 – View all accounts
6 – Write a check through a specific Checking Account
7 – Withdraw funds from a specific account
8 – Deposit funds into an account
9 – Exit Program
enter your choice
5
to view all accounts
CheckingAccount getAccno()=524, getBalance()=1500.0
SavingsAccountAccount [balance=2564.0]
welcome to the mustang bank
please choose the following opnions
1 – Create a new Checking Account
2 – Create a new Savings Account
3 – Delete an existing account
4 – View a specific account
5 – View all accounts
6 – Write a check through a specific Checking Account
7 – Withdraw funds from a specific account
8 – Deposit funds into an account
9 – Exit Program
enter your choice
9
do you want to exit or not type y/n
y

Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w
Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w
Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w
Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w
Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w
Write a Java program for the following: This banking system is to be created for this assignment. The program will consist of five(5) classes: MustangBanking (w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site