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

Please only use if else, switch, and while statments only and no using char vari

ID: 3752210 • Letter: P

Question

Please only use if else, switch, and while statments only and no using char variable thank you. this is also not a main class so please dont use main method in in this thank you. also use java.arraylist thanks nothing else like hashmap

(java) create a bank account class with the following code in it:

1. one attribute called savingsaccounts to store list of accounts for the customers inputs

2. you must create a banking method that will be able to deposit or withdraw an amount to or from the account. • use an integer to select to (1) deposit, (2) withdraw or (0) quit; It will continue to repear options till 0 is pressed to quit; you should not relay on the order/index of the list to determine the customer’s account. You should make sure the account’s name matches the customer’s name.

Explanation / Answer

****************************

CODE

*****************************

import java.util.ArrayList;

import java.util.Scanner;

class Account {

   private String name;

   private double balance;

   public Account(String name, double balance) {

       super();

       this.name = name;

       this.balance = balance;

   }

   /**

   * @return the name

   */

   public String getName() {

       return name;

   }

   /**

   * @param name the name to set

   */

   public void setName(String name) {

       this.name = name;

   }

   /**

   * @return the balance

   */

   public double getBalance() {

       return balance;

   }

   /**

   * @param balance the balance to set

   */

   public void setBalance(double balance) {

       this.balance = balance;

   }

}

public class BankAccount {

   ArrayList<Account> savingsaccounts = new ArrayList<>();

   Scanner sc = new Scanner(System.in);

   public void inputcustdetails() {

       while(true) {

           String name;

           double balance;

           System.out.print("Enter the customer name (d to quit) : ");

           name = sc.next();

           if ("d".equalsIgnoreCase(name))

               break;

           System.out.print("Enter the opening balance : ");

           balance = sc.nextDouble();

           savingsaccounts.add(new Account(name, balance));  

       }

   }

   public void banking() {

       int choice;

       String name;

       while(true) {

           System.out.println("(1) Deposit, (2) withdraw or (0) Quit : ");

           System.out.println("Enter your choice : ");

           choice = sc.nextInt();

           switch(choice) {

           case 1:

               System.out.println("Enter the account name : ");

               name = sc.next();

               if (savingsaccounts.contains(name)) {

                   Account acc = savingsaccounts.get(savingsaccounts.indexOf(name));

                   double amt;

                   System.out.println("Enter the deposit amount : ");

                   amt = sc.nextDouble();

                   acc.setBalance(acc.getBalance() + amt);

                   savingsaccounts.set(savingsaccounts.indexOf(name), acc);

               } else {

                   System.out.println("No such account exists!!!");

               }

               break;

           case 2:

               System.out.println("Enter the account name : ");

               name = sc.next();

               if (savingsaccounts.contains(name)) {

                   Account acc = savingsaccounts.get(savingsaccounts.indexOf(name));

                   double amt;

                   System.out.println("Enter the withdrawal amount : ");

                   amt = sc.nextDouble();

                   acc.setBalance(acc.getBalance() - amt);

                   savingsaccounts.set(savingsaccounts.indexOf(name), acc);

               } else {

                   System.out.println("No such account exists!!!");

               }

               break;

           case 0:

               return;

           default:

               System.out.println("You have entered wrong input!!");

           }

       }

   }

}