ATM Withdrawal Check

This program checks if withdrawal is possible based on balance.

Problem Statement

Write a Java program that checks if withdrawal is possible based on account balance.

Source Code

1 public class ATMWithdrawal {
2 public static void main(String[] args) {
3 double balance = 5000;
4 double withdraw = 3000;
5 if(withdraw <= balance) {
6 System.out.println("Withdrawal successful. Remaining balance: " + (balance - withdraw) + " - Eduinq");
7 } else {
8 System.out.println("Insufficient balance - Eduinq");
9 }
10 }
11 }

Program Output

Withdrawal successful. Remaining balance: 2000.0 - Eduinq

Explanation

The program checks if the withdrawal amount is less than or equal to the balance. - If true, it deducts the amount and prints the remaining balance. - Otherwise, it prints insufficient balance. - This simulates ATM withdrawal logic, ensuring that transactions only proceed when funds are available. - It demonstrates how conditional statements can enforce financial rules. Conclusion: Shows how ATM withdrawal checks can be implemented using if-else.

Quick Links to Explore