Skip to content

A simple command-line Java application that simulates ATM operations with PIN authentication, deposit, withdrawal, and balance checking. Perfect for beginners to practice object-oriented programming and basic Java syntax.

Notifications You must be signed in to change notification settings

yogeshkumarsaini/ATM-Machine-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ATM Simulation in Java

This is a simple Java program that simulates basic ATM machine operations on the command line. It demonstrates object-oriented principles along with conditionals, loops, and user input handling in Java.


πŸ”Ή Features

  • PIN authentication
  • Withdraw money
  • Deposit money
  • Balance check
  • Exit option

πŸ”Ή Concepts Used

  • OOP (Classes & Objects)
  • Conditionals
  • Loops
  • Scanner input

πŸ“Œ Java Code – ATM Simulation

Click to expand the Java code
import java.util.Scanner;

class ATM {
    private int pin = 1234;
    private double balance = 5000;

    public boolean authenticate(int enteredPin) {
        return pin == enteredPin;
    }

    public void checkBalance() {
        System.out.println("Current Balance: β‚Ή" + balance);
    }

    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("Deposit successful.");
        } else {
            System.out.println("Invalid amount.");
        }
    }

    public void withdraw(double amount) {
        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("Please collect your cash.");
        } else {
            System.out.println("Insufficient balance or invalid amount.");
        }
    }
}

public class ATMMachine {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ATM atm = new ATM();

        System.out.print("Enter PIN: ");
        int enteredPin = sc.nextInt();

        if (!atm.authenticate(enteredPin)) {
            System.out.println("Invalid PIN. Access denied.");
            return;
        }

        int choice;
        do {
            System.out.println("\n--- ATM MENU ---");
            System.out.println("1. Check Balance");
            System.out.println("2. Deposit");
            System.out.println("3. Withdraw");
            System.out.println("4. Exit");
            System.out.print("Choose option: ");
            choice = sc.nextInt();

            switch (choice) {
                case 1:
                    atm.checkBalance();
                    break;
                case 2:
                    System.out.print("Enter deposit amount: ");
                    atm.deposit(sc.nextDouble());
                    break;
                case 3:
                    System.out.print("Enter withdraw amount: ");
                    atm.withdraw(sc.nextDouble());
                    break;
                case 4:
                    System.out.println("Thank you for using ATM.");
                    break;
                default:
                    System.out.println("Invalid option.");
            }
        } while (choice != 4);

        sc.close();
    }
}

πŸš€ How to Run

  1. Copy the code into a file named ATMMachine.java.
  2. Compile the program:
    javac ATMMachine.java
  3. Run it:
    java ATMMachine

πŸ“ Notes

  • Default PIN: 1234
  • Initial Balance: β‚Ή5000
  • This project is for learning and demonstration purposes only.

About

A simple command-line Java application that simulates ATM operations with PIN authentication, deposit, withdrawal, and balance checking. Perfect for beginners to practice object-oriented programming and basic Java syntax.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages