ATM Program in Java

In this blog, we will explore a brief overview of ATM systems and delve into the importance and functionality of ATM programs.

ATM systems, also known as cash machines or ATMs, are electronic devices that allow individuals to perform a range of financial transactions without the need for human assistance. Initially introduced as a means to withdraw cash, ATMs have evolved to offer a wide array of services, making them a cornerstone of modern banking.

Working of ATM Program in Java

Let’s check out the working of each operation:

Withdraw: The withdrawal process involves obtaining the withdrawal amount from the user, deducting it from the user’s account balance, and displaying a message confirming the successful withdrawal and providing transaction details.

Deposit: This operation allows users to deposit funds into their account. It involves getting the deposit amount from the user, adding it to their account balance, and displaying a message confirming the successful deposit and providing transaction details.

Check the balance: This operation allows users to view their current account balance by retrieving their total balance and displaying it on the screen, allowing the user to view their available funds.

Exit: The user can exit the current transaction mode by closing any open connections or terminating the application, which may include closing any open connections or terminating the application.

It is important to ensure proper input validation, handle error conditions, and maintain the integrity and security of user transactions in the ATM Program in Java.

Also, learn about Spy Number in Java here!

Importance and Functionality of ATM Programs:

  • Convenience and Accessibility
  • Time-saving and Efficiency
  • Enhanced Financial Control
  • Cash Management
  • Integration with Banking Services

Example of ATM Program in Java

//import required classes and packages   
import java.util.Scanner;  
//create ATMExample class to implement the ATM functionality  
public class ATMExample  
    //main method starts   
    public static void main(String args[] )  
        //declare and initialize balance, withdraw, and deposit  
        int balance = 100000, withdraw, deposit;  
        //create scanner class object to get choice of user  
        Scanner sc = new Scanner(;  
            System.out.println("Automated Teller Machine");  
            System.out.println("Choose 1 for Withdraw");  
            System.out.println("Choose 2 for Deposit");  
            System.out.println("Choose 3 for Check Balance");  
            System.out.println("Choose 4 for EXIT");  
            System.out.print("Choose the operation you want to perform:");  
            //get choice from user  
            int choice = sc.nextInt();  
                case 1:  
        System.out.print("Enter money to be withdrawn:");  
        //get the withdrawl money from user  
        withdraw = sc.nextInt();  
        //check whether the balance is greater than or equal to the withdrawal amount  
        if(balance >= withdraw)  
            //remove the withdrawl amount from the total balance  
            balance = balance - withdraw;  
            System.out.println("Please collect your money\n");  
            //show custom error message   
            System.out.println("Insufficient Balance");  
                case 2:  
        System.out.print("Enter money to be deposited:");  
        //get deposite amount from te user  
        deposit = sc.nextInt();  
        //add the deposit amount to the total balanace  
        balance = balance + deposit;  
        System.out.println("Your Money has been successfully depsited");  
                case 3:  
        //displaying the total balance of the user  
        System.out.println("Balance : "+balance);  
                case 4:  
        //exit from the menu  

Explanation of the code:

The provided code implements an ATM program in Java that allows users to perform various banking operations such as withdrawing funds, depositing funds, checking the account balance, and exiting the program.

The code begins by initializing the balance variable with an initial amount. It then creates a Scanner object to read user input. Inside a while loop, the program displays a menu of options to the user.

When the user selects option 1 (withdraw), the program prompts the user to enter the withdrawal amount. It checks the balance, deducts the withdrawal amount if it is sufficient. Alternatively, if the balance is insufficient, the program displays an error message indicating the lack of funds.

Option 2 (deposit) prompts the user to enter the deposit amount, which is added to the balance.

If user selects Option 3 (check balance) then it simply displays the current balance to the user.

Option 4 (exit) terminates the program by calling System.exit(0).

The while loop continues indefinitely, enabling the user to perform multiple transactions until they choose to exit the program. This allows for a seamless flow of operations and provides a user-friendly experience.

Overall, the code provides a basic implementation of an ATM program in Java, allowing users to perform essential banking operations.

Check out our blog on Prime Number in Java here!


Automated Teller MachineChoose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:1
Enter money to be withdrawn:500
Please collect your money
Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform:3
Balance : 99500

Automated Teller Machine
Choose 1 for Withdraw
Choose 2 for Deposit
Choose 3 for Check Balance
Choose 4 for EXIT
Choose the operation you want to perform

We hope that this article has helped you learn more about the “ATM Program in Java” and other important information. Stay tuned for more updates from Java programming blogs. You can also visit our Newtum website for more information on various programs such as PHP, C Programming for kids, and more.

About The Author

Leave a Reply