Java ATM Simulation Project – Step-by-Step Program with Code

By Vandu
May 2, 2025

Follow us on


Learn how to create a simple ATM simulation program in Java. This beginner-friendly guide includes source code, complete explanation, and practical examples.

Java ATM Simulation Project – Step-by-Step Program with Code

Create a Program for ATM Simulation in Java Programming

Creating an ATM simulation program is one of the most common Java projects for beginners. It helps you understand key programming concepts like:

  • Conditional statements

  • Loops

  • User input

  • Methods (functions)

  • Basic object-oriented programming (OOP)

In this blog, we’ll build a simple ATM simulation in Java with full code and step-by-step explanation in simple terms.


🧠 What Will This ATM Program Do?

This ATM simulation will:

  • Ask the user to log in using a PIN.

  • Display a menu:

    1. Check Balance

    2. Deposit Money

    3. Withdraw Money

    4. Exit

  • Perform operations based on the user’s choice.

  • Continue until the user chooses to exit.


💻 Java Code: ATM Simulation

 

📝 Step-by-Step Explanation

import java.util.Scanner;

public class ATMSimulator {
    // Initial account balance
    private static double balance = 1000.0;

    // Default PIN
    private static final int PIN = 1234;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int enteredPin;

        // Step 1: Ask user to enter the PIN
        System.out.print("Enter your 4-digit PIN: ");
        enteredPin = scanner.nextInt();

        if (enteredPin == PIN) {
            int choice;

            // Loop until user chooses to exit
            do {
                // Display menu
                System.out.println("\n===== ATM Menu =====");
                System.out.println("1. Check Balance");
                System.out.println("2. Deposit Money");
                System.out.println("3. Withdraw Money");
                System.out.println("4. Exit");
                System.out.print("Choose an option: ");
                choice = scanner.nextInt();

                switch (choice) {
                    case 1:
                        checkBalance();
                        break;
                    case 2:
                        depositMoney(scanner);
                        break;
                    case 3:
                        withdrawMoney(scanner);
                        break;
                    case 4:
                        System.out.println("Thank you for using our ATM. Goodbye!");
                        break;
                    default:
                        System.out.println("Invalid choice. Please try again.");
                }

            } while (choice != 4);

        } else {
            System.out.println("Incorrect PIN. Access Denied.");
        }

        scanner.close();
    }

    // Method to check balance
    public static void checkBalance() {
        System.out.println("Your current balance is: ₹" + balance);
    }

    // Method to deposit money
    public static void depositMoney(Scanner scanner) {
        System.out.print("Enter amount to deposit: ₹");
        double amount = scanner.nextDouble();

        if (amount > 0) {
            balance += amount;
            System.out.println("₹" + amount + " deposited successfully.");
            checkBalance();
        } else {
            System.out.println("Invalid deposit amount.");
        }
    }

    // Method to withdraw money
    public static void withdrawMoney(Scanner scanner) {
        System.out.print("Enter amount to withdraw: ₹");
        double amount = scanner.nextDouble();

        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("₹" + amount + " withdrawn successfully.");
            checkBalance();
        } else {
            System.out.println("Invalid amount or insufficient balance.");
        }
    }
}

✅ Step 1: Define Required Variables

private static double balance = 1000.0;
private static final int PIN = 1234;
  • We store the balance and PIN.

  • The PIN is final so it can’t be changed.


✅ Step 2: Ask User to Enter PIN

System.out.print("Enter your 4-digit PIN: ");
enteredPin = scanner.nextInt();
  • This checks if the person trying to use the ATM knows the correct PIN.


✅ Step 3: Show ATM Menu Using Loop

do {
   // Display menu
} while (choice != 4);
  • A loop is used to keep showing the menu until the user chooses option 4 (Exit).


✅ Step 4: Perform Actions Based on User Choice

switch (choice) {
   case 1: checkBalance(); break;
   case 2: depositMoney(scanner); break;
   case 3: withdrawMoney(scanner); break;
   case 4: // exit
  • Based on the user's selection, the relevant method is called.


✅ Step 5: Create Helper Methods

checkBalance()

Shows current balance.

depositMoney(scanner)

Asks user for amount, adds it to balance.

withdrawMoney(scanner)

Checks if enough balance is there. If yes, subtracts amount.


🔚 Conclusion

You just created a basic ATM simulation in Java! 🚀

This project helps you understand input/output, decision making, loops, and methods—all essential Java concepts. You can improve this program by adding features like:

  • Multiple users/accounts

  • Transaction history

  • Login attempts limit

  • GUI using Java Swing


© 2025 Pay18News. All rights reserved.