Question
JAVA Programing You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to
JAVA Programing
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.
****** BankAccount Class ******
public class BankAccount { private String name; private long accountNumber; private int PIN; private double balance; public BankAccount() { this.name = ""; this.accountNumber = 0; this.PIN = 0; this.balance = 0; } public BankAccount(long accountNumber, int PIN) { this.name = ""; this.accountNumber = accountNumber; this.PIN = PIN; this.balance = 0; } public String getName() { return name; } public long getAccountNumber() { return accountNumber; } public int getPIN() { return PIN; } public double getBalance() { return balance; } public void setName(String name) { this.name = name; } public void setAccountNumber(long accountNumber) { this.accountNumber = accountNumber; } public void setPIN(int PIN) { this.PIN = PIN; } public void setBalance(double balance) { if (balance > 0) { this.balance = balance; } } public void withdrawal(double amount) { if (amount > 0) { this.balance = this.balance - amount; } } public void deposit(double amount) { if (amount > 0) { this.balance = this.balance + amount; } } public void transferFunds(double amount,BankAccount toBankAccount) { if (amount > 0) { this.balance = this.balance - amount; toBankAccount.balance = toBankAccount.balance + amount; } } @Override public String toString() { return "id: " + accountNumber + ", name: " + name + ", pin: " + PIN + ", balance: $" + balance; } }
****** BankAccountTest Class *****
public class BankAccountTest { public static void main(String[] args) { BankAccount myAccount = new BankAccount(522233333, 1234); myAccount.setName("John"); myAccount.deposit(100); System.out.println("Balance: $"+myAccount.getBalance()); myAccount.deposit(200); System.out.println("Balance: $"+myAccount.getBalance()); myAccount.withdrawal(50); System.out.println("Balance: $"+myAccount.getBalance()); System.out.println(myAccount); System.out.println(); BankAccount anotherAccount = new BankAccount(); //default constructor anotherAccount.setName("Alex"); anotherAccount.setAccountNumber(124444244); anotherAccount.setPIN(4321); anotherAccount.deposit(200); System.out.println("Balance: $"+anotherAccount.getBalance()); anotherAccount.deposit(100); System.out.println("Balance: $"+anotherAccount.getBalance()); anotherAccount.withdrawal(150); System.out.println("Balance: $"+anotherAccount.getBalance()); System.out.println(anotherAccount); System.out.println(); myAccount.transferFunds(70, anotherAccount); System.out.println("Balance in My Account: $"+myAccount.getBalance()); System.out.println("Balance in Another Account: $"+anotherAccount.getBalance()); } }
****** BankAccount Class ******
public class BankAccount { private String name; private long accountNumber; private int PIN; private double balance; public BankAccount() { this.name = ""; this.accountNumber = 0; this.PIN = 0; this.balance = 0; } public BankAccount(long accountNumber, int PIN) { this.name = ""; this.accountNumber = accountNumber; this.PIN = PIN; this.balance = 0; } public String getName() { return name; } public long getAccountNumber() { return accountNumber; } public int getPIN() { return PIN; } public double getBalance() { return balance; } public void setName(String name) { this.name = name; } public void setAccountNumber(long accountNumber) { this.accountNumber = accountNumber; } public void setPIN(int PIN) { this.PIN = PIN; } public void setBalance(double balance) { if (balance > 0) { this.balance = balance; } } public void withdrawal(double amount) { if (amount > 0) { this.balance = this.balance - amount; } } public void deposit(double amount) { if (amount > 0) { this.balance = this.balance + amount; } } public void transferFunds(double amount,BankAccount toBankAccount) { if (amount > 0) { this.balance = this.balance - amount; toBankAccount.balance = toBankAccount.balance + amount; } } @Override public String toString() { return "id: " + accountNumber + ", name: " + name + ", pin: " + PIN + ", balance: $" + balance; } }
****** BankAccountTest Class *****
public class BankAccountTest { public static void main(String[] args) { BankAccount myAccount = new BankAccount(522233333, 1234); myAccount.setName("John"); myAccount.deposit(100); System.out.println("Balance: $"+myAccount.getBalance()); myAccount.deposit(200); System.out.println("Balance: $"+myAccount.getBalance()); myAccount.withdrawal(50); System.out.println("Balance: $"+myAccount.getBalance()); System.out.println(myAccount); System.out.println(); BankAccount anotherAccount = new BankAccount(); //default constructor anotherAccount.setName("Alex"); anotherAccount.setAccountNumber(124444244); anotherAccount.setPIN(4321); anotherAccount.deposit(200); System.out.println("Balance: $"+anotherAccount.getBalance()); anotherAccount.deposit(100); System.out.println("Balance: $"+anotherAccount.getBalance()); anotherAccount.withdrawal(150); System.out.println("Balance: $"+anotherAccount.getBalance()); System.out.println(anotherAccount); System.out.println(); myAccount.transferFunds(70, anotherAccount); System.out.println("Balance in My Account: $"+myAccount.getBalance()); System.out.println("Balance in Another Account: $"+anotherAccount.getBalance()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started