Java Menu Driven Banking Application

In this article we are going to see a menu driven banking application by using Java programming language.

Java Menu Driven Banking Application

We will write a program for basic banking applications which mostly involve in

  1. Opening Account
  2. Depositing Money
  3. Withdrawing Money
  4. Account Statement

For the below menu driven program, we have used below user defined method.

  • openAcc( ) – Asks the user for details and creates the account
  • accInfo( ) – Displays the user name, account type and account number
  • balanceInq( ) – Displays the balance available
  • withdraw( ) – Withdraw amount from the user account if possible.
  • deposit( ) – Deposit amount into the bank account

Approach:

  • Inside a while loop display all the functionalities.
  • Ask the user to enter their choice.
  • Use switch case for navigation.
  • Upon account creation ask the user to enter their user name, account type, account number and balance. Store them all in static variables.
  • Now to display the user info display the user name, account number and account type to the console.
  • Now to see the the account balance, print out the available balance to the console.
  • If the user want to deposit into their account, ask the user for deposit amount then add the value to the current balance and display the new balance.
  • If the user wants to withdraw from the account, ask the user for withdraw amount then check if the entered amount is not greater than the balance then print the new balance after subtracting the amount, else print insufficient balance.

Program:

import java.util.*;
import java.lang.*;

public class Main
{
    static String username= null;
    static String acctNo= null;
    static String accType= null;
    static long balance = 0;

        // Driver method
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int ch=1;
        // Loop to select the choices
        while(ch!=0)
        {
            // Menu
            System.out.println("---\t Services Available \t---");
            System.out.println("1. Open a new account");
            System.out.println("2. Show account information");
            System.out.println("3. Balance inquiry");
            System.out.println("4. Withdraw money");
            System.out.println("5. Deposit money");
            System.out.println("6. Exit");
            System.out.println("Enter your choice number");
            ch = sc.nextInt();
           
            // Switch case to use the menu
            switch(ch)
            {
                case 1: openAcc();
                        System.out.println("\n");
                        break;
                case 2: accInfo();
                        System.out.println("\n");
                        break;
                case 3: balanceEnq();
                        System.out.println("\n");
                        break;
                case 4: withdraw();
                        System.out.println("\n");
                        break;
                case 5: deposit();
                        System.out.println("\n");
                        break;
                case 6: System.out.println("Thank you!!");
                        System.exit(0);
                        break;
                default: System.out.println("Wrong Input!!! Retry");
            }
        }
    }
    
    // To open an account
    static void openAcc()
    {
        //Ask the user to enter his name
        System.out.println("Enter your name: ");
        Scanner sc = new Scanner(System.in);
        username = sc.nextLine();
        //Ask the user to enter his account number (generally Bank provides AC no.)
        System.out.println("Enter your account number: ");
        acctNo = sc.nextLine();
        //Ask the user to enter his Account type
        System.out.println("Enter the account type you want to create: ");
        accType = sc.nextLine();
        //Ask the user to enter his opening account balance
        System.out.println("Enter your opening account balance: ");
        balance = sc.nextInt();
        
        System.out.println("Welcome "+username);
        System.out.println("Your account has been successfully created.");
    }
   
    // To view the account number and other information
    static void accInfo()
    {
        System.out.println("Welcome "+username);
        System.out.println("Your account number is "+acctNo+" and is a "+accType+" account");
    }

    // To view the balance
    static void balanceEnq(){
        System.out.println("Your current account balance is: "+balance);
    }

    // To withdraw from the account
    static void withdraw(){
        System.out.println("Enter amount to withdraw from your account: ");
        Scanner sc = new Scanner(System.in);
        long amount = sc.nextLong();
        //If your withdraw amount is more than your available balance
        //then you can not withdraw due to insufficient fund
        if(amount>balance)
            System.out.println("Insufficient Funds!!!");
        else
        {
            //deducting from available balance
            balance -= amount;
            System.out.println("The amount of "+amount+" has been successfully debited.");
            System.out.println("Your new balance is: "+balance);
        }
    }

    // To deposit money to the account
    static void deposit(){
        System.out.println("Enter amount to deposit in your account: ");
        Scanner sc = new Scanner(System.in);
        long amount = sc.nextLong();
        //adding to available balance
        balance += amount;
        System.out.println("The amount of "+amount+" has been successfully credited.");
        System.out.println("Your new balance is: "+balance);
    }
}

Output:

--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
2
Welcome null
Your account number is null and is a null account


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
1
Enter your name: 
Shankar
Enter your account number: 
227755449933
Enter the account type you want to create: 
Saving
Enter your opening account balance: 
5000
Welcome Shankar
Your account has been successfully created.


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
3
Your current account balance is: 5000


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
2
Welcome Shankar
Your account number is 227755449933 and is a Saving account


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
5
Enter amount to deposit in your account: 
6000
The amount of 6000 has been successfully credited.
Your new balance is: 11000


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
3
Your current account balance is: 11000


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
4
Enter amount to withdraw from your account: 
5500
The amount of 5500 has been successfully debited.
Your new balance is: 5500


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
5
Enter amount to deposit in your account: 
2500
The amount of 2500 has been successfully credited.
Your new balance is: 8000


--- Services Available ---
1. Open a new account
2. Show account information
3. Balance inquiry
4. Withdraw money
5. Deposit money
6. Exit
Enter your choice number
6
Thank you!!

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.