Google Advertisement

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

Google Advertisement
πŸ”₯ Read with Full Features on Our Website

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

Published on 02 May 2025
By Vandu

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:

Google Advertisement

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:


πŸ’» 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;

βœ… Step 2: Ask User to Enter PIN

System.out.print("Enter your 4-digit PIN: ");
enteredPin = scanner.nextInt();

βœ… Step 3: Show ATM Menu Using Loop

do {
   // Display menu
} while (choice != 4);

βœ… 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

βœ… 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:

❀️ Like πŸ’¬ Comment πŸ”— Share
Google Advertisement
πŸ‘‰ View Full Version on Main Website β†—
Google Advertisement
πŸ‘‰ Read Full Article on Website