You are on page 1of 4

This java program has following menus:

1. Dispay All
2. Search By Account
3. Deposit
4. Withdrawal
5. Exit

Initialy we add some(N)customer to the bank and we can display all account details
using menu 1) menu2) is used to search the bank account,menu3) is used to deposit
money in particuar
account,menu 4) is used to manager withdrawa and menu 5) is used to exit from the
program.

Program:

import java.uti.Scanner;
class Bank
{
private string accno;
private string name;
private ong balance;

Scanner kB=new Scanner(System.in);

//method to open an account

void openAccount()
{
System.out.println("Enter Account No");

accno=kB.next();
System.out.println("Enter Name:");
name=kB.next();
System.out.println("Enter Balance:");
balance=kB.nextLong();
}
//method to dispay account details
void showAccount()
{
System.out.println(accno+","+name+","+balance);
}

//method to Deposit money


void deposit()
{
long amnt;
System.out.println("Enter amount you want to deposit:");
amnt=kb.next long();
balance=balance+amnt;
}
//method to withdrawal money
void withdrawal ()
{
long amnt;
System.out.println("Enter amnt you want to withdawa:");
amnt=kB.nextlong();
if(balance>=amnt)
{
balance=balance-amnt;
}
else
{
System.out.println("less balance..transaction failed..");
}
}
//method to search an account number
boolen search(String acn)
{
if(accno.equals(acn);
{
showAccount();
retrurn(true);
}

return(false);
}
class ExBank
{

public static void main(String args[]


{
Scanner kB=new Scanner(system.in);
//create initial account
System.out.println("How many custmer you want toinput:");
int n=kB.nextint();
Bank C[]=new Bank(n);
for(i=0;i<c.lenght; i++)
{
C[i]=new Bank();
C[i] 0penAccount();
}
//run loop until menu 5 is not pressed
int ch;
do
{
Systen.out.println("Main menu\n
1. Display All\n
2.Search by Account\n
3.Deposit\n
4.Withdrawal
5.Exit");
Systen.out.println("you choice:");
ch=kB.nextint();
switch(ch)
{
case1:
for(int i=0;i<C lenght; i++)

{
C[i]=showAccount();
}
break;

case2:
System.out.println("EnterAccount NO you want ");
String acn=kBnext();
boolen found=false;
for(inti=0;i<C.length;i++)
{
found=C[i].search(acn);
if (found)
{
break;
}
case3:
System.out.println("Enter Account No:");
acn=kB.next();
found=false;
for(inti=0;i<C.length;i++)
{
found=C[i].search(acn);
if (found)
{
C[i].deposit();
break;
}
}
if(!found)
{
System.out.println("search failed..Account not exit:")
}
break;

case4:
System.out.println("Enter Account No:");
acn=kB.next();
found=false;
for(inti=0;i<C.length;i++)
{
found=C[i].search(acnn);
if (found)
{
C[i].withdrawal();
break;
}
}
if(!found)
{
System.out.println("search failled..Account not exit:")
}
break;

case5:
System.out.printlln("Good Bye..");
break;
}
}
while(ch!=5);
}
}

You might also like