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

Hello i am mainly stuck on the arraylist. i wonderstand how to make arraylist, b

ID: 3701887 • Letter: H

Question

Hello i am mainly stuck on the arraylist. i wonderstand how to make arraylist, but what i confused is despoiting the balance into the arraylist and transfering them etc.

The goal of this assignment is to give you some experience building a program that uses objects. You must work in teams of 2 to complete this assignment. You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to the user to allow the user to select a transaction like deposit, withdraw, transfer, create a bank account, and quit the program. The program should allow a user to perform multiple transactions until they quit the program by selecting the quit option. The program must perform all operations on the BankAccount objects your program will store. The operations must search through the collection of BankAccount objects and find the correct object to perform the operation on. When a user creates an account, your program should create a new BankAccount object with the user's input values and store it in an Array or ArrayList.

private String name;

   private int accountNumber;

   private int PIN;

   private double balance;

  

   public BankAccount(int accN, int pin) {

       accountNumber = accN;

       PIN = pin;

   }

  

   public BankAccount () {

       name = "Undefined";

       accountNumber = 0;

       PIN = 0;

       balance = 0;

   }

   public String getName() {

       return name;

   }

   public int getAccountNumber() {

       return accountNumber;

   }

   public int getPIN() {

       return PIN;

   }

   public double getBalance() {

       return balance;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setAccountNumber(int accountNumber) {

       this.accountNumber = accountNumber;

   }

   public void setPIN(int pIN) {

       PIN = pIN;

   }

   public void setBalance(double balance) {

       this.balance = balance;

   }

  

   public void withdrawal(double amount) {

       if(amount <= balance) {

           balance = balance - amount;

       }

   }

   public void deposit(double amount) {

       balance += amount;

   }

  

   public void transferFunds (double amount, BankAccount toBankAccount) {

      

       if(amount >= balance) {

           toBankAccount.setBalance(amount + toBankAccount.getBalance());

           balance -= amount;

       }

      

   }

  

   @Override

   public String toString() {

       return "{id:"+accountNumber+", name:"+name+", pin:"+PIN+", balance:$"+balance+"}";

   }

}

#########

public class BankAccountTest {

   public static void main(String[] args) {

      

       BankAccount myAccount = new BankAccount(526323450, 1234);

       myAccount.setName("Pravesh");

       myAccount.setBalance(345.64);

      

       System.out.println(myAccount);

      

       BankAccount anotherAccount = new BankAccount(); //default constructor

      

       System.out.println(anotherAccount);

   }

}

/*

Sample run:

{id:526323450, name:Pravesh, pin:1234, balance:$345.64}

{id:0, name:Undefined, pin:0, balance:$0.0}

*/

Explanation / Answer

Could u plz check the output...As i developed based on we do our bank transactions.Like while we deposit we dont need to enter Pin number.Nut while withdrawl amount we need to enter pin number.Plz check and let me know if u need any modifications.Thank u

__________________

BankAccount.java

public class BankAccount {

private String name;

private int accountNumber;

private int PIN;

private double balance;

public BankAccount(int accN, int pin) {

accountNumber = accN;

PIN = pin;

}

public BankAccount() {

name = "Undefined";

accountNumber = 0;

PIN = 0;

balance = 0;

}

public String getName() {

return name;

}

public int getAccountNumber() {

return accountNumber;

}

public int getPIN() {

return PIN;

}

public double getBalance() {

return balance;

}

public void setName(String name) {

this.name = name;

}

public void setAccountNumber(int accountNumber) {

this.accountNumber = accountNumber;

}

public void setPIN(int pIN) {

PIN = pIN;

}

public void setBalance(double balance) {

this.balance = balance;

}

public void withdrawal(double amount) {

if (amount <= balance) {

balance = balance - amount;

}

}

public void deposit(double amount) {

balance += amount;

}

public void transferFunds(double amount, BankAccount toBankAccount) {

if (amount >= balance) {

toBankAccount.setBalance(amount + toBankAccount.getBalance());

balance -= amount;

}

}

@Override

public String toString() {

return "{id:" + accountNumber + ", name:" + name + ", pin:" + PIN

+ ", balance:$" + balance + "}";

}

}

_______________________

Test.java

import java.util.ArrayList;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

int choice;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

ArrayList<BankAccount> accounts=new ArrayList<BankAccount>();

BankAccount acc1 = new BankAccount(111455678, 1234);

acc1.setName("Pravesh");

acc1.setBalance(50000);

accounts.add(acc1);

BankAccount acc2 = new BankAccount(111455679, 4224);

acc2.setName("Sachin");

acc2.setBalance(26000);

accounts.add(acc2);

BankAccount acc3 = new BankAccount(111455680, 5555);

acc3.setName("Ramesh");

acc3.setBalance(32000);

accounts.add(acc3);

do

{

//displaying the menu

System.out.println(" Please select an option");

System.out.println("1 - Deposit");

System.out.println("2 - Withdrawal");

System.out.println("3 - Transfer");

System.out.println("4 - Create Bank Account");

System.out.println("5 - Exit");

System.out.print(" Enter Choice :");

//getting the choice entered by the user

choice=sc.nextInt();

//Based on the user choice the corresponding case will be executed

switch(choice)

{

case 1:{

int flag=0,indx=-1;

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

int accNo=sc.nextInt();

for(int i=0;i<accounts.size();i++)

{

if(accounts.get(i).getAccountNumber()==accNo)

{

flag=1;

indx=i;

}

}

  

if(flag==1)

{

System.out.print("How much amount you want to deposit :$");

double amt=sc.nextDouble();

accounts.get(indx).deposit(amt);

System.out.println("You account Balance :$"+accounts.get(indx).getBalance());

}

else

{

System.out.println("**No BankAccount with the Account Number **");

}

break;

}

case 2:{

int flag=0,indx=-1;

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

int accNo=sc.nextInt();

System.out.println("Enter Pin Number :");

int pin=sc.nextInt();

for(int i=0;i<accounts.size();i++)

{

if(accounts.get(i).getAccountNumber()==accNo && accounts.get(i).getPIN()==pin)

{

flag=1;

indx=i;

}

}

if(flag==1)

{

System.out.print("How much amount you want to withdraw :$");

double amt=sc.nextDouble();

if(accounts.get(indx).getBalance()>=amt)

{

accounts.get(indx).withdrawal(amt);

System.out.println("You account Balance :$"+accounts.get(indx).getBalance());

}

else

{

System.out.println("** Insufficient Balance **");

}

}

else

{

System.out.println("**No BankAccount with the Account Number or Invalid Pin**");

}

break;

}

case 3:{

int flag1=0,indx1=-1,flag2=0,indx2 = -1;

System.out.println("Enter the account Number to which you want to transfer :");

int toAccNo=sc.nextInt();

System.out.println("Enter the account Number from which you want to transfer :");

int fromAccNo=sc.nextInt();

System.out.println("Enter Pin Number :");

int pin=sc.nextInt();

for(int i=0;i<accounts.size();i++)

{

if(accounts.get(i).getAccountNumber()==toAccNo)

{

flag1=1;

indx1=i;

}

}

for(int i=0;i<accounts.size();i++)

{

if(accounts.get(i).getAccountNumber()==fromAccNo && accounts.get(i).getPIN()==pin)

{

flag2=1;

indx2=i;

}

}

if(flag1==0)

{

System.out.println("** Account Number to which you want to transfer is invalid **");

}

if(flag2==0)

{

System.out.println("** Account Number from which you want to transfer is invalid **");

}

if(flag1==1 && flag2==1)

{

System.out.print("How much amount you want to transfer :$");

double transferAmt=sc.nextDouble();

if(accounts.get(indx2).getBalance()>=transferAmt)

{

accounts.get(indx2).withdrawal(transferAmt);

accounts.get(indx2).transferFunds(transferAmt,accounts.get(indx1));

System.out.println("-- Transaction Successful --");

}

else

{

System.out.println("** Insufficient balance to Transfer **");

}

}

break;

}

case 4:{

System.out.print("Enter Account Number :");

int accNo=sc.nextInt();

System.out.print("Enter Pin Number :");

int pin=sc.nextInt();

System.out.print("Enter Name :");

String name=sc.nextLine();

sc.nextLine();

System.out.print("Enter Initial Deposit :$");

double amt=sc.nextDouble();

BankAccount b=new BankAccount(accNo, pin);

b.setName(name);

b.setBalance(amt);

accounts.add(b);

break;

}

case 5:{

break;

}

}

}while(choice!=5);

}

}

______________________

Output:


Please select an option
1 - Deposit
2 - Withdrawal
3 - Transfer
4 - Create Bank Account
5 - Exit

Enter Choice :1
Enter the account Number :
111455678
How much amount you want to deposit :$5000
You account Balance :$55000.0

Please select an option
1 - Deposit
2 - Withdrawal
3 - Transfer
4 - Create Bank Account
5 - Exit

Enter Choice :2
Enter the account Number :
111455670
Enter Pin Number :
5555
**No BankAccount with the Account Number or Invalid Pin**

Please select an option
1 - Deposit
2 - Withdrawal
3 - Transfer
4 - Create Bank Account
5 - Exit

Enter Choice :2
Enter the account Number :
111455680
Enter Pin Number :
5555
How much amount you want to withdraw :$12000
You account Balance :$20000.0

Please select an option
1 - Deposit
2 - Withdrawal
3 - Transfer
4 - Create Bank Account
5 - Exit

Enter Choice :3
Enter the account Number to which you want to transfer :
111455678
Enter the account Number from which you want to transfer :
111455680
Enter Pin Number :
5555
How much amount you want to transfer :$8000

-- Transaction Successful --

Please select an option
1 - Deposit
2 - Withdrawal
3 - Transfer
4 - Create Bank Account
5 - Exit

Enter Choice :5

__________________Thank You

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