Coders Packet

Online Banking Application in Java

By GUJJU SNEHA BHARATHI

This package is about the Online Banking Application using Java Programming. This is a very basic programming package written in Java that can be used for simple banking applications.

This package of Online Banking Application is written in Java Programming Language.

In this we will be coding the simple bank operations like check balance, deposit, withdraw, exit, etc. Implementation of Functions, Loops, Constructors, and usage of input from the user using the Scanner class, Print statements, etc are being done. 

Firstly, we will import the java.util.Scanner class to invoke the Scanner class which takes the input from the user.

import java.util.Scanner;

 

Further, we will be constructing a class that includes a constructor for initializing the name and ID of the account holder, and in the same class, all the methods like deposit, withdrawal, the previous transaction, and menu are constructed with their functions. In the menu method, we will be calling all the other methods using switch case for invoking the functions. We can also find the usage of do-while loop in this class.

class BankAccount
{
    int Balance;
    int Last_Transaction;
    String Accountholder_Name;
    String Account_Id;
    
    BankAccount(String aname,String aid)
    {
        Accountholder_Name = aname;
        Account_Id = aid;
    }
    
    void Deposits(int amount)
    {
        if(amount!=0)
        {
            Balance = Balance + amount;
            Last_Transaction = amount;
        }
    }
    void Withdrawal(int amount)
    {
        if(amount!=0)
        {
            Balance = Balance - amount;
            Last_Transaction = -amount;
        }
    }
    void TraceLast_Transaction()
    {
        if(Last_Transaction > 0)
        {
            System.out.println("Amount Deposited: "+Last_Transaction);
        }
        else if(Last_Transaction < 0)
        {
            System.out.println("Amount Withdrawn: "+Math.abs(Last_Transaction));
        }
        else
        {
            System.out.println("No recent transaction occured");
        }
        
    }
    void Menu()
    {
       char option='\0';
       Scanner scanner = new Scanner(System.in);
       System.out.println("Welcome "+Accountholder_Name);
       System.out.println("Your ID is "+Account_Id);
       System.out.println("\n");
       System.out.println("A. Check Existence Balance");
       System.out.println("B. Deposit");
       System.out.println("C. Withdraw");
       System.out.println("D. Recent_Transaction");
       System.out.println("E. Exit");
       
       do
       {
           System.out.println(" This banking system is totally SECURED!!!");
           System.out.println("Enter your Option");
           System.out.println("------------------------------------------");
           option = scanner.next().charAt(0);
           System.out.println("\n");
           
           switch(option)
           {
               case 'A':
                   System.out.println("--------------------------------------");
                   System.out.println("Current Balance: = "+Balance);
                   System.out.println("--------------------------------------");
                   System.out.println("\n");
                   break;
                   
               case 'B':
                   System.out.println("--------------------------------------");
                   System.out.println("Enter an amount that is to be deposited:");
                   System.out.println("--------------------------------------");
                   int amount1 = scanner.nextInt();
                   Deposits(amount1);
                   System.out.println("\n");
                   break;
                   
               case 'C':
                   System.out.println("--------------------------------------");
                   System.out.println("Enter an amount to withdraw:");
                   System.out.println("--------------------------------------");
                   int amount2 = scanner.nextInt();
                   Withdrawal(amount2);
                   System.out.println("\n");
                   break;
                 
               case 'D':
                   System.out.println("--------------------------------------");
                   TraceLast_Transaction();
                   System.out.println("--------------------------------------");
                   System.out.println("\n");
                   break;
                   
               case 'E':
                   System.out.println("--------------------------------------");
                   System.out.println("Thank you");
                   System.out.println("--------------------------------------");
                   
               default:
                   System.out.println("Invalid!! Please Try Again");
                   break;       
               
           }
          
       }while(option!= 'E');
       
       System.out.println("Thank you for using our services");
    }  
}

 

 

Finally, we will create a main method which is the primary method of any programming language. We will create a main method in a different class with a public access specifier. Over the main method, we will create an object for the constructor for invoking all the functions which are in the constructor class.

import java.util.Scanner;

public class OnlineBanking {

    public static void main(String[] args) {
        BankAccount obj = new BankAccount("CustomerNameAA","ABC1234");
        obj.Menu();
        
    }
    
}

 

Output:

Download project

Reviews Report

Submitted by GUJJU SNEHA BHARATHI (gujjusnehabharathi)

Download packets of source code on Coders Packet