Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Last active August 29, 2022 19:21
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save shohan4556/a8afad40aa5fd8c77251 to your computer and use it in GitHub Desktop.
Save shohan4556/a8afad40aa5fd8c77251 to your computer and use it in GitHub Desktop.
java Bank Account Management Project.
package bankmanagment;
import java.util.*;
/**
*
* @author Shohan
* Bank Account Class
* // Main ClassName -- "Main"
*/
class Account{
String name,acc_type;
int Acc_num,Acc_Balance;
Account(){
}
Account(String n,int acc_num,int b,String a_t){
name=n;
Acc_num=acc_num;
Acc_Balance=b;
acc_type=a_t;
}
} // end class
class create_account extends Account{
create_account(String n,int acc_num,int b,String a_t){ // pass name and account type
name=n;
Acc_num=acc_num;
Acc_Balance=b;
acc_type=a_t;
}
create_account(){
super();
}
void insert(String n,int acc_num,String a_t){ // input user name, account number and type
name=n;
acc_type=a_t;
Acc_num=acc_num; // generate random number
Acc_Balance=0;
}
void display_details(){
System.out.println("Depositor Name :" +name);
System.out.println("Account Number : "+Acc_num);
System.out.println("Account Balance : "+Acc_Balance);
System.out.println("Account Type : "+acc_type);
}
void deposite(int acc_num,int money){
Acc_Balance=money;
}
int withdraw(int withd){
Acc_Balance=Acc_Balance-withd;
return Acc_Balance;
}
} // end class
public class Main {
public static void main(String args[]){
String user_name=null,type;
type = null;
int balance=0,tmp=0;
int withd=0,cb=0;
// to generate Random Account Number
int aNumber = 0;
aNumber = (int)((Math.random() * 9000)+1000);
create_account user = new create_account("user",0,0,"savings"); // initilaize -- name,acc_number,Balance,Type
Scanner in = new Scanner(System.in);
Scanner strng=new Scanner(System.in);
int userChoice;
boolean quit = false;
do {
System.out.println("1. Create Account");
System.out.println("2. Deposit money");
System.out.println("3. Withdraw money");
System.out.println("4. Check balance");
System.out.println("5. Display Account Details");
System.out.println("0. to quit: \n");
System.out.print("Enter Your Choice : ");
userChoice = in.nextInt();
switch (userChoice) {
case 1:
System.out.print("Enter your Name : ");
user_name=strng.nextLine();
System.out.print("Enter Accout Type : ");
type=in.next();
user.insert(user_name, aNumber, type); // inserted
System.out.println("\n\tYour Account Details\n\tDont Forget Account Number\n");
System.out.println("**************************");
user.display_details();
break;
case 2: // deposite
System.out.print("Enter your account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
System.out.print("Enter Amount Of Money : ");
balance=in.nextInt();
user.Acc_Balance=balance;
System.out.println("\t Successfully Deposited.");
}
else
System.out.println("Wrong Accoount Number.");
break;
case 3: // withdraw money
System.out.print("Enter your account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
if(user.Acc_Balance==0)
System.out.print("Your Account is Empty.");
else{
System.out.print("Enter Amout Of Money : ");
withd=in.nextInt();
if(withd>user.Acc_Balance){
System.out.print("Enter Valid Amout of Money : ");
withd=in.nextInt();
}
else
cb= user.withdraw(withd);
System.out.println("Your Current Balance : "+cb);
}
}
else
System.out.println("Wrong Accoount Number.");
break;
case 4: // check balance
System.out.print("Enter your Account Number : ");
tmp=in.nextInt();
if(tmp==user.Acc_num){
System.out.println("Your Current Balance : "+user.Acc_Balance);
}
else
System.out.println("Wrong Accoount Number.");
break;
case 5: // display all info
System.out.print("Enter your Account Number :");
tmp=in.nextInt();
if(tmp==user.Acc_num){
user.display_details();
}else
System.out.println("Wrong Accoount Number.");
break;
case 0:
quit = true;
break;
default:
System.out.println("Wrong Choice.");
break;
}
System.out.println("\n");
} while (!quit);
System.out.println("Thanks !");
} // end main function
} // end mian class
@issah003
Copy link

hello I know very well that am in best group, am mohammed issah I want to learn java programming can someone help me.

@Ken-Sarowiwa
Copy link

welcome on board issah mohammed, you will learn alot in a very short time.

@yottabytedev
Copy link

I want to create an accounts management system for my college . Can you help me to create it . I am new in coding field this is my 2nd project . But first in database management system . So I need guidance .

@Jaidv
Copy link

Jaidv commented May 24, 2018

In this program, Same Account Number is generated randomly in all members please give me a complete solution.

@mehtaaditya
Copy link

Bank class is not available. use generics for this type of appliction

@somnadh
Copy link

somnadh commented Jul 20, 2018

ok...what about backend??

@KLU40099
Copy link

KLU40099 commented Sep 6, 2018

Bro! There is some logic missing in case 3 i.e., in Withdrawl. There should be some more lines added between line-126 to line 129 because after entering the valid amount it shows "Your current balance is 0". So I think that should be corrected.

@Shraddhasaini
Copy link

1.The account number is same for all the accounts created.
2. If we deposite twice,rather than adding the two, only displays the second one as current balance. Like I deposite 100 bucks and than deposite 10 bucks again. Instead of getting 110 we get 10 when we check balance.
3. The current balance is 0 everytime we withdraw some money.

@zekariasbirbirsa
Copy link

best

@shruti2389
Copy link

Hi
I copy pasted (retyped) this program as it is. But only output i am able to get is
Enter your choices
1
2
3
4
5

when I enter a choice..it asks for bank account number and whatever number i type....it exits the program & again gives the same output. If the account number I give is too long..it gives inputmismatchexception.

Also , by tyoing in 1st option...the account does not get created. it asks for account type and again exits. can anyone plz help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment