Written by Sai Sandeep Thota on July 12, 2013 in Java > Programming

Java Program to Solve Simple Banking Problem

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This is our 100th article on ProgrammingUnit. We Thank all our readers for encouraging us. The journey has been pretty happy so far and we wish you’ll be with us all the way 🙂

We have already written C++ Program to solve Simple Banking Problem, Now let us solve this using Java. In this program we are using two classes, bankInternal and Bank which carry out the required operations.

bankInternal has a constructor which gathers all the required information like account number, initial balance of the account. Deposit method is used to deposit money in the account and withdraw method is used to withdraw money from the account, if there is sufficient balance in the account.

Bank contains the main method which creates object to the bankInternal class. We have created object named myObj and calling only deposit() and withdraw() methods as we don’t need to call bankInternal() because it is a constructor and it will be called once the object is created.

Java Program to Solve Simple Banking Problem

import java.util.Scanner;

class bankInternal {
    int acno;
    float bal=0;
    Scanner get = new Scanner(System.in);
    bankInternal()
    {
        System.out.println("Enter Account Number:");
        acno = get.nextInt();
        System.out.println("Enter Initial Balance:");
        bal = get.nextFloat();        
    }
    void deposit()
    {
        float amount;
        System.out.println("Enter Amount to be Deposited:");
        amount = get.nextFloat();
        bal = bal+amount;
        System.out.println("Deposited! Account Balance is "+bal);
    }
    void withdraw()
    {
        float amount;
        System.out.println("Enter Amount to be Withdrawn:");
        amount = get.nextFloat();
        if(amount<bal)
        {
            bal = bal-amount;
            System.out.println("Amount Withdrawn!! Available Balance: "+bal);
        }
        else
        {
            System.out.println("Insufficient funds!!");
        }
    }
}

public class Bank {
    public static void main(String[] args)
    {
        bankInternal myObj = new bankInternal();
        myObj.deposit();
        myObj.withdraw();       
    }
}

Output:
Java Program to Solve Simple Banking Problem

{ 1 comment… read it below or add one }

Anoop negi September 6, 2017 at 7:50 am

Woow..!! Thnkuu sir..!! Kafi help mili meko..!!

Reply

Leave a Comment

Previous post:

Next post: