Banking system software code in Java

package com.physicsinfo;

import javax.swing.*;
import java.util.Scanner;

class account{
    int amount, acc_no; String name;
    void display(int acct_no, String name, int bal){
        System.out.println(acct_no+" "+name+" "+bal);
    }
    void deposit(int amnt){
        amount = amount +amnt;
        System.out.println("Deposit successful. Your new balance is: "+amount);
    }
    void withdraw(int wdr){
        if (wdr>amount){
            System.out.println("Insufficient balance.");
        }
        else {
            amount = amount - wdr;
            System.out.println("Withdraw successful. Your new balance is: "+amount);
        }

    }

}

public class Main {
    public static void main(String args[]){
    int amt, wd, operation;
    account a=new account();
    String[] data = new String[3];
    Scanner sc = new Scanner(System.in);
        System.out.print("Enter the account number: ");
        data[0] = sc.next();
        a.acc_no = Integer.parseInt(data[0]);
        System.out.print("Enter the account name: ");
        data[1] = sc.next();
        a.name = data[1];
        System.out.print("Enter the initial balance: ");
        data[2] = sc.next();
        a.amount = Integer.parseInt(data[2]);
        do{
        System.out.println("1. Deposit");
        System.out.println("2. Withdraw");
        System.out.println("3. Check balance");
        System.out.println("4. Display info");
        System.out.println("5. Exit");
        System.out.print("Which operation do you want to perform: ");
        operation = sc.nextInt();
        switch(operation){
            case 1:
                System.out.print("Enter the amount you want to deposit: ");
                amt = sc.nextInt();
                a.deposit(amt);
                break;
            case 2:
                System.out.print("Enter the amount you want to withdraw: ");
                wd = sc.nextInt();
                a.withdraw(wd);
                break;
            case 3:
                System.out.println("Your current balance is: "+a.amount);break;
            case 4: a.display(a.acc_no, a.name, a.amount); break;
        }}while(operation!=5);

    }
}

Leave a Comment

Your email address will not be published.