Simple Banking Application Using Java With Source Code

Simple Banking Application Using Java​

Introduction:

Simple Banking Application is a simple Java project for beginners to start their career in coding. You’ll learn about Scanner class to take inputs, and the basics of strings, loops, methods, and conditional statements. Here, simple banking operations like deposit, withdrawal, checking balance, exit, etc. 

Explanation:

Java is a powerful programming language that is commonly used for building enterprise-level applications. One of the most popular application domains for Java is banking. Java provides a robust set of libraries and frameworks that make it easy to develop a banking application.

In this article, we will take a look at how to build a simple banking application using Java. Our application will have the following basic functionality:

  • Check balance

  • Deposit money

  • Withdraw money

  • Exit the application

The first step in building our application is to create a new Java project. We will use the command-line interface to create a new project and set up the project structure. Once the project is set up, we can start writing the code for our application.

The main class of our application will be called “Bank”. In this class, we will define the main method and the basic functionality of our application. The main method will be responsible for displaying the menu to the user and handling the user’s input.

The menu will consist of four options:

  1. Check balance

  2. Deposit money

  3. Withdraw money

  4. Exit the application

The user will be prompted to select an option by entering a number between 1 and 4. If the user enters an invalid option, the application will display an error message and prompt the user to enter a valid option.

Source Code:

Get Discount on Top Educational Courses

Brand NameDiscount InformationCoupon Codes Link
Educative.io20% discount on Educative courses and plans
W3Schools20% discount on W3Schools courses
KodeKloud10% discount on KodeKloud courses and plans
GeeksforGeeks30% discount on GeeksforGeeks courses
Target Test Prep20% discount on Target Test Prep
Coding Ninjas₹5000 discount on Coding Ninjas courses
Skillshare40% discount on Skillshare
DataCamp50% discount on DataCamp
365 Data Science57% discount on 365 Data Science Plans
Get SmarterFlat 20% discount on Get Smarter courses
SmartKeedaFlat 40% discount on SmartKeeda courses
StackSocial20% discount on StackSocial courses
				
					import java.util.Scanner;

public class Bank {
  static double balance = 0;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int option = 0;
    while (option != 4) {
      System.out.println("Welcome to the Bank of Java");
      System.out.println("1. Check Balance");
      System.out.println("2. Deposit");
      System.out.println("3. Withdraw");
      System.out.println("4. Exit");
      System.out.print("Enter an option: ");
      option = scanner.nextInt();

      switch (option) {
        case 1:
          checkBalance();
          break;
        case 2:
          deposit();
          break;
        case 3:
          withdraw();
          break;
        case 4:
          exit();
          break;
        default:
          System.out.println("Invalid option. Try again.");
          break;
      }
    }
  }

  public static void checkBalance() {
    System.out.println("Your current balance is $" + balance);
  }

  public static void deposit() {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the amount to deposit: $");
    double amount = scanner.nextDouble();
    balance += amount;
    System.out.println("$" + amount + " has been deposited to your account.");
    checkBalance();
  }

  public static void withdraw() {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the amount to withdraw: $");
    double amount = scanner.nextDouble();
    if (amount > balance) {
      System.out.println("Insufficient funds.");
    } else {
      balance -= amount;
      System.out.println("$" + amount + " has been withdrawn from your account.");
    }
    checkBalance();
  }

  public static void exit() {
    System.out.println("Thank you for banking with us. Have a great day!");
  }
}
				
			

The check balance option will display the current balance of the user’s account. The deposit and withdraw options will prompt the user to enter the amount of money they want to deposit or withdraw. If the user tries to withdraw more money than they have in their account, the application will display an error message.

The exit option will close the application and display a farewell message to the user.

Output:

Simple Banking Application Using Java
Simple Banking Application Using Java

Find More Projects

electronics Store website using html CSS and JavaScript Introduction Hello coders, welcome to another new project. As you know our today’s project …

Digital Marketing Agency website Using HTML, CSS and JavaScript Introduction Hello coders, welcome to another new blog. Today in this project we’ll …

Fruit Slicer Game Using HTML CSS And JavaScript Introduction Hey coders, welcome to another new blog. Today in this blog we’ve created …

Event Organizers Website Using Html Css And JavaScript Introduction Hello coders, welcome to another new blog. As you know that our today’s …

Shape Clicker Game Using HTML CSS And JavaScript Introduction Hey coders, welcome to another new blog. Today in this article we’ve made …

responsive College Website Using Html CSS & JavaScript Introduction Hello coders, welcome to another new blog. Today in this blog post we’ll …