Java Program to Display the ATM Transaction (original) (raw)
Last Updated : 19 Dec, 2025
ATM (Automated Teller Machine) transaction system allows users to perform basic banking operations such as withdrawing money, depositing funds, and checking account balance. This Java program simulates core ATM functionality using simple methods and conditional logic.
Supported ATM Operations
The program supports the following operations:
- **Withdraw: Deducts a specified amount from the account if sufficient balance is available
- **Deposit: Adds a specified amount to the account balance
- **Check Balance: Displays the current account balance
- **Exit: Terminates the transaction flow
Approach
**A. Withdraw:
- Accepts the withdrawal amount as input
- Checks whether the available balance is sufficient
- Deducts the amount if possible, otherwise prints an insufficient funds message
**B. Deposit:
- Accepts the deposit amount as input
- Adds the amount to the existing balance
- Displays a success message along with the updated balance
**C. Check Balance: Prints the current balance available in the account
**D. Exit: Ends the transaction process
Java `
import java.io.*;
public class GFG{ public static void displayBalance(int balance) { System.out.println("Current Balance : " + balance); } // Withdraw amount and update balance public static int amountWithdrawing(int balance, int withdrawAmount) { System.out.println("\nWithdrawing Amount : " + withdrawAmount);
if (balance >= withdrawAmount) {
balance = balance - withdrawAmount;
System.out.println("Please collect your money and card.");
displayBalance(balance);
} else {
System.out.println("Sorry! Insufficient Funds");
System.out.println();
}
return balance;
}
// Deposit amount and update balance
public static int amountDepositing(int balance, int depositAmount) {
System.out.println("\nDepositing Amount : " + depositAmount);
balance = balance + depositAmount;
System.out.println("Deposit successful.");
displayBalance(balance);
return balance;
}
public static void main(String args[]) {
int balance = 10000;
int withdrawAmount = 5000;
int depositAmount = 2000;
// Display initial balance
displayBalance(balance);
// Perform withdrawal
balance = amountWithdrawing(balance, withdrawAmount);
// Perform deposit
balance = amountDepositing(balance, depositAmount);
}}
`
Output
Current Balance : 10000
Withdrawing Amount : 5000 Please collect your money and card. Current Balance : 5000
Depositing Amount : 2000 Deposit successful. Current Balance : 7000
**Explanation:
- main() initializes balance, withdrawAmount, and depositAmount, then displays the initial balance using displayBalance(balance).
- amountWithdrawing() checks sufficient balance and deducts the withdrawal amount using balance = balance - withdrawAmount.
- amountDepositing() adds the deposit amount using balance = balance + depositAmount and prints the updated balance.