Simple Banking Application Using Java With Source Code
![Simple Banking Application Using Java](https://codewithcurious.com/wp-content/uploads/2023/01/Handwritten-Notes-7-1024x576.png.webp)
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:
Check balance
Deposit money
Withdraw money
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:
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](https://codewithcurious.com/wp-content/uploads/2023/01/capture1.png.webp)
![Simple Banking Application Using Java](https://codewithcurious.com/wp-content/uploads/2023/01/Capture-2.png.webp)
Find More Projects
Resume Builder Application using Java With Source Code Graphical User Interface [GUI] Introduction: The Resume Builder Application is a powerful and user-friendly …
Encryption Tool using java with complete source Code GUI Introduction: The Encryption Tool is a Java-based GUI application designed to help users …
Movie Ticket Booking System using Java With Source Code Graphical User Interface [GUI] Introduction: The Movie Ticket Booking System is a Java …
Video Call Website Using HTML, CSS, and JavaScript (Source Code) Introduction Hello friends, welcome to today’s new blog post. Today we have …
promise day using html CSS and JavaScript Introduction Hello all my developers friends my name is Gautam and everyone is welcome to …
Age Calculator Using HTML, CSS, and JavaScript Introduction Hello friends, my name is Gautam and you are all welcome to today’s new …