This website uses cookies to ensure you get the best experience on our website.
Learn more
Got it!
Home
Coding problems
DS & Algo. ▾
Languages ▾
Web. ▾
Programs ▾
Aptitude ▾
Interview ▾
CS Subjects ▾
More ▾
Home » Java programs
Java program for banking management
system
In this java program, we will learn how to create a small project like banking system? In this
program, we are using some of the banking related options like deposit, withdrawal etc.
Submitted by IncludeHelp, on October 28, 2017
This java program has following main menus:
1. Display All
2. Search By Account
3. Deposit
4. Withdrawal
5. Exit
Initially, we will add some (N) customers to the bank and then we can display all account details
using menu 1), menu 2) is used to search the bank account, menu 3) is used to deposit money in
particular account, menu 4) is used to manager withdrawal and menu 5) is used to exit from the
program.
Program
import java.util.Scanner;
class Bank
{
private String accno;
private String name;
private long 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
{
public static void 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)
{
case 1:
for(int i=0;i<C.length;i++)
{
C[i].showAccount();
}
break;
case 2:
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;
case 3:
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;
case 4:
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;
case 5:
System.out.println("Good Bye..");
break;
}
}
while(ch!=5);
}
}
Output
How Many Customer U Want to Input : 2
Enter Account No: 101
Enter Name: Chintu
Enter Balance: 25000
Enter Account No: 102
Enter Name: Alexander
Enter Balance: 30000
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
1
101,Chintu,25000
102,Alexander,30000
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
2
Enter Account No U Want to Search...: 102
102,Alexander,30000
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
2
Enter Account No U Want to Search...: 105
Search Failed..Account Not Exist..
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
3
Enter Account No : 102
102,Alexander,30000
Enter Amount U Want to Deposit :
25000
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
3
Enter Account No : 105
Search Failed..Account Not Exist..
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
4
Enter Account No : 102
102,Alexander,55000
Enter Amount U Want to withdraw :
15000
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
4
Enter Account No : 105
Search Failed..Account Not Exist..
Main Menu
1.Display All
2.Search By Account
3.Deposit
4.Withdrawal
5.Exit
Ur Choice :
5
Good Bye..
TOP Interview Coding Problems/Challenges
Run-length encoding (find/print frequency of letters in a string)
Sort an array of 0's, 1's and 2's in linear time complexity
Checking Anagrams (check whether two string is anagrams or not)
Relative sorting algorithm
Finding subarray with given sum
Find the level in a binary tree with given sum K
Check whether a Binary Tree is BST (Binary Search Tree) or not
1[0]1 Pattern Count
Capitalize first and last letter of each word in a line
Print vertical sum of a binary tree
Print Boundary Sum of a Binary Tree
Reverse a single linked list
Greedy Strategy to solve major algorithm problems
Job sequencing problem
Root to leaf Path Sum
Exit Point in a Matrix
Find length of loop in a linked list
Toppers of Class
Print All Nodes that don't have Sibling
Transform to Sum Tree
Shortest Source to Destination Path
Comments and Discussions
Ad: Are you a blogger? Join our Blogging forum.
Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web
programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates
ABOUT SECTION
» About us
» Contact us
» Feedback
» Privacy policy
STUDENT'S SECTION
» Internship
» Certificates
» Content Writers of the Month
SUBSCRIBE
» Facebook
» LinkedIn
» Subscribe through email
© https://www.includehelp.com some rights reserved.