0% found this document useful (0 votes)
67 views3 pages

Bank Management

This Java code defines a Bank class with methods to open an account, display account details, deposit money, and withdraw money. It also defines an ExBank class with a main method that allows a user to input a number of customer accounts, then displays a menu to search accounts, deposit/withdraw funds, and exit. The menu is in a do-while loop that runs until the user selects the exit option.

Uploaded by

Arihant Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views3 pages

Bank Management

This Java code defines a Bank class with methods to open an account, display account details, deposit money, and withdraw money. It also defines an ExBank class with a main method that allows a user to input a number of customer accounts, then displays a menu to search accounts, deposit/withdraw funds, and exit. The menu is in a do-while loop that runs until the user selects the exit option.

Uploaded by

Arihant Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

class Bank
{
private String accno;
private String name;
privatelong balance;

Scanner KB=new Scanner(System.in);

//method to open an account


void openAccount()
{
System.out.print("Enter Account No: ");
accno=KB.next();
System.out.print("Enter Name: ");
name=KB.next();
System.out.print("Enter Balance: ");
balance=KB.nextLong();
}

//method to display account details


void showAccount()
{
System.out.println(accno+","+name+","+balance);
}

//method to deposit money


void deposit()
{
long amt;
System.out.println("Enter Amount U Want to Deposit : ");
amt=KB.nextLong();
balance=balance+amt;
}

//method to withdraw money


void withdrawal()
{
long amt;
System.out.println("Enter Amount U Want to withdraw : ");
amt=KB.nextLong();
if(balance>=amt)
{
balance=balance-amt;
}
else
{
System.out.println("Less Balance..Transaction Failed..");
}
}

//method to search an account number


boolean search(String acn)
{
if(accno.equals(acn))
{
showAccount();
return(true);
}
return(false);
}
}

class ExBank
{
publicstaticvoid main(String arg[])
{
Scanner KB=new Scanner(System.in);

//create initial accounts


System.out.print("How Many Customer U Want to Input : ");
int n=KB.nextInt();
Bank C[]=new Bank[n];
for(int i=0;i<C.length;i++)
{
C[i]=new Bank();
C[i].openAccount();
}

//run loop until menu 5 is not pressed


int ch;
do
{
System.out.println("Main Menu\n
1.Display All\n
2.Search By Account\n
3.Deposit\n
4.Withdrawal\n
5.Exit");
System.out.println("Ur Choice :");
ch=KB.nextInt();
switch(ch)
{
case1:
for(int i=0;i<C.length;i++)
{
C[i].showAccount();
}
break;

case2:
System.out.print("Enter Account No U Want to
Search...: ");
String acn=KB.next();
boolean found=false;
for(int i=0;i<C.length;i++)
{
found=C[i].search(acn);
if(found)
{
break;
}
}
if(!found)
{
System.out.println("Search Failed..Account Not
Exist..");
}
break;

case3:
System.out.print("Enter Account No : ");
acn=KB.next();
found=false;
for(int i=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
Exist..");
}
break;

case4:
System.out.print("Enter Account No : ");
acn=KB.next();
found=false;
for(int i=0;i<C.length;i++)
{
found=C[i].search(acn);
if(found)
{
C[i].withdrawal();
break;
}
}
if(!found)
{
System.out.println("Search Failed..Account Not
Exist..");
}
break;

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy