230k views
3 votes
"The goal of this assignment is to give you some experience building a program that uses objects. 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."

User Stefania
by
2.9k points

1 Answer

1 vote

Answer:

see explaination

Step-by-step explanation:

Please find my detailed implementation.

I have tested with Single Bank account object.

You can create array list of Bank Account in test program:

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;

}

}

atOverride //change the at with the at symbol

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

}

}

User Dusktreader
by
3.3k points