Page 1 of 1

ShowAccount: Given the accounts array as input, print all the customers’ information in a nice format such as shown belo

Posted: Thu May 26, 2022 9:22 am
by answerhappygod
ShowAccount: Given the accounts array as input, print all the
customers’ information in a nice format such as shown below:
Displaying the information of all the accounts.
***************************************
Name of account holder: jack
Account no.: 123
Balance: 20
Name of account holder: max
Account no.: 654
Balance: 100
**************************************
given code:
package submission;
import java.util.Scanner;
public class BankingApp {
public static String[][] accounts;// each row of
this array, corresponds to a customer, holding 1.account_number
2.name 3.balance

/**
* open new accounts
* @param accounts, a 2d array
of strings. Each row will represent an account: [account_number,
name, balance]
*/
public static void openAccount(String[][]
accounts, Scanner sc) {
for (int i = 0; i <
accounts.length; i++) {
System.out.print("Enter Account No: ");
String
accno = sc.next();

System.out.print("Enter Name: ");
String
name = sc.next();

System.out.print("Enter Balance: ");
String
balance = sc.next();
accounts[0] = accno;

accounts[1] = name;

accounts[2] = balance;
}
}
/**
* displaying all accounts' details
* @param accounts, a 2d array
of strings. Each row represents an account: [account_number, name,
balance]
*/
public static void showAccount(String[][] accounts) {
System.out.println("Displaying
the information of all the accounts.");

System.out.println("***************************************");
//TODO loop over all the
accounts and display their details
System.out.println("***************************************");

}
...
public static void main(String arg[]) {
Scanner sc = new
Scanner(System.in);

System.out.print("How many
customers would you like to have? ");
int n = sc.nextInt();


// this 2d array is used to
hold the information of customers
accounts = new
String[n][3];
//create initial
accounts
openAccount(accounts,
sc);
// loop runs until number
6 is not pressed to exit
int ch;
do {

System.out.println("\n ***Banking System
Application***");

System.out.println(" 1. Display all account details \n 2.
Search by Account number\n 3. Deposit the amount \n 4. Withdraw the
amount \n 5. Add new accounts \n 6. Exit ");

System.out.println("Enter your choice: ");
ch =
sc.nextInt();
switch
(ch) {
case 1:
showAccount(accounts);break;
case
2:

System.out.print("Enter account no. you
want to search: ");

String ac_no = sc.next();

boolean result=search(ac_no);
if (!result) {

System.out.println("No
account exists for the given account number.");

}

break;
case
3:

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

ac_no = sc.next();

long amt;

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

amt = sc.nextLong();
String d_result =deposit(ac_no,
amt);

if (!d_result.equals("failed")) {


System.out.println("Deposit was successful. New balance: [" +
d_result + "]");

}
break;
case
4:

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

ac_no = sc.next();

System.out.println("Enter the amount you
want to withdraw: ");

amt = sc.nextLong();
String w_result =withdrawal(ac_no,
amt);

if (!w_result.equals("failed")) {

if
(w_result.equals("low")) {


System.out.println("Oops... your balance is not enough to
withdraw the given amount");

}else {


System.out.println("Withdrawal successful. New balance: [" +
w_result + "]");

}

}
break;
case
5:

System.out.println("Enter the information
for the new account.");

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

String accno = sc.next();

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

String name = sc.next();

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

String balance = sc.next();
boolean n_result =
openNewAccount(accno, name, balance);

if (n_result) {

System.out.println("New
account was added successfully");

}

break;
case
6:

System.out.println("Sad to see you
go!");

break;
}
}
while (ch != 6);
}
}