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

Program using java Upon starting the program, the user should be asked if they a

ID: 3844856 • Letter: P

Question

Program using java

Upon starting the program, the user should be asked if they are an existing member of the "bank".

- If the user indicates that they are not a member, they should be prompted to enter their information for registration.

- If the user is a member they should be prompted to enter their login credentials (username and password).

- If the credentials are incorrect, they should be prompted again or kicked back to the main menu (after three tries?).

- If the credentials are correct, they should be taken to the members' menu where they have the options of

1. view a list of their accounts

2. make a deposit

3. make a withdrawal

4. open a new account

5. close an existing account

6. logout (return to main menu)

After completing one of the actions (except logging out), they should be returned to the members' menu.

- an id number

- a balance

- a type (String)

- a link to the owner's object

- methods to deposit and withdraw money

- any other variables/methods necessary to the function of the program

The member class should contain:

- an id number

- a username (String)

- a password (String)

- a name

- an array of accounts owned by the member

- any other variables/methods necessary to the function of the program

The main class should contain an array of members and variables for any other data it must keep track of.

Explanation / Answer

import java.util.Scanner;
public class BankApp {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Bank myBank = new Bank();
  
int choice = 2;
int op;
do {
//display menu to user
//ask user for his choice and validate it (make sure it is between 1 and 6)
System.out.println("If you are an existing customer: a. Yes b. No");
switch(op)
{
Case a: System.out.println("Go for any option from 1 to 6");
break;
Case b: System.out.println("Go for next option 1.");
break;
}
System.out.println("1) open a new account");
System.out.println("2) make a deposit");
System.out.println("3) make a withdrawal");
System.out.println("4) Print short account information");
System.out.println("5) Print account transactions");
System.out.println("6) logout");
System.out.println();
System.out.print("Enter choice 1 to 6 ");
choice = s.nextInt();
switch (choice) {
case 1: System.out.println("Enter a customer name");
String cn = s.next();
System.out.println("Enter a opening balance");
double d = s.nextDouble();
System.out.println("Account was created with number: " + myBank.openNewAccount(cn, d));
break;
case 2: System.out.println("Enter a account number");
int an = s.nextInt();
System.out.println("Enter a deposit amount");
double da = s.nextDouble();
myBank.depositTo(an, da);
break;
case 3: System.out.println("Enter your account number");
int acn = s.nextInt();
System.out.println("Enter the withdraw amount");
double wa = s.nextDouble();
myBank.withdrawFrom(acn, wa);
break;
case 4: System.out.println("Enter your account number");
int anum = s.nextInt();
myBank.printAccountInfo(anum);
break;
//case 5: ... break;
}
}
while (choice != '6');
}

static class Bank {
private BankAccount[] accounts;   
private int numOfAccounts;

public Bank() {
accounts = new BankAccount[100];
numOfAccounts = 0;
}

public int openNewAccount(String customerName, double openingBalance) {

BankAccount b = new BankAccount(customerName, openingBalance);
accounts[numOfAccounts] = b;
numOfAccounts++;
return b.getAccountNum();
}

public void depositTo(int accountNum, double amount) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
accounts[i].deposit(amount);
System.out.println("Required Amount is deposited successfully");
return;
}
}
System.out.println("Account number not found.");
}

public void withdrawFrom(int accountNum, double amount) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
accounts[i].withdraw(amount);
System.out.println("Required Amount has been withdrawn successfully");
return;
}
}
System.out.println("Account number was not found.");
}


public void printAccountInfo(int accountNum) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
System.out.println(accounts[i].getAccountInfo());
return;
}
}
System.out.println("Account number not found.");
}

public void printAccountInfo(int accountNum, int n) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
System.out.println(accounts[i].getAccountInfo());
System.out.println(accounts[i].getTransactionInfo(n));
return;
}
}
System.out.println("Account number was not found.");
}

}

static class BankAccount{

private int accountNum;
private String customerName;
private double balance;
private double[] transactions;
private static int noOfAccounts=0;
private int numOfTransactions;

public String getAccountInfo(){
return "Account No.: " + accountNum + " Customer Name: " + customerName + " TotalBalance:" + balance +" ";
}

public String getTransactionInfo(int n)
{
numOfTransactions = n;
return n;

}

public BankAccount(String x, double y){
customerName = x;
balance = y;
noOfAccounts ++;
accountNum = noOfAccounts;
transactions = new double[100];
transactions[0] = balance;
numOfTransactions = 1;
}

public int getAccountNum(){
return accountNum;
}
public void deposit(double amount){

if (amount<=0) {
System.out.println("Please enter positive number");
}
else
{
balance = balance + amount;
transactions[numOfTransactions] = amount;
numOfTransactions++;
}
}
public void withdraw(double amount)
{
if (amount<=0){
System.out.println("please enter a positive number");
}
else
{
if (balance < amount) {
System.out.println("Insufficient balance in your account.");
} else {
balance = balance - amount;
transactions[numOfTransactions] = amount;
numOfTransactions++;
}
}
}
}
}