Simple Banking Application Using Java With Source Code
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:
Get Discount on Top Educational 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:
Find More Projects
URL Shortener Using Python Django Introduction: Long URLs can be shortened into short, shareable links with the help of the URL Shortener …
User Authentication System Using Python Django Introduction: The implementation of safe and adaptable user authentication in Django is the main goal of …
The E-Learning System using Java with a Graphical User Interface (GUI) Introduction The E-Learning System is developed using Java (with a Graphical …
Weather App Using Python Django Introduction: When a user enters the name of a city, the Weather App retrieves current weather information. …
Quiz App Using Python Django Introduction: Users can take quizzes in a variety of subjects, see their results, and monitor their progress …
resume screener in python using python introduction The hiring process often begins with reviewing numerous resumes to filter out the most suitable …