ATM Withdrawal with PIN

This program checks PIN and withdrawal eligibility.

Problem Statement

Write a Java program that verifies ATM PIN and checks withdrawal eligibility.

Source Code

1 public class ATMWithdrawalPin {
2 public static void main(String[] args) {
3 int pin = 1234;
4 int enteredPin = 1234;
5 double balance = 5000;
6 double withdraw = 2000;
7 if(enteredPin == pin) {
8 if(withdraw <= balance) {
9 System.out.println("Withdrawal successful. Remaining balance: " + (balance - withdraw) + " - Eduinq");
10 } else {
11 System.out.println("Insufficient balance - Eduinq");
12 }
13 } else {
14 System.out.println("Invalid PIN - Eduinq");
15 }
16 }
17 }

Program Output

Withdrawal successful. Remaining balance: 3000.0 - Eduinq

Explanation

The program first checks if the entered PIN matches the stored PIN. If true, it then checks if withdrawal is possible based on balance. Only if both conditions are satisfied, withdrawal is successful. Otherwise, it prints the reason for failure. Shows how nested if can handle ATM PIN and withdrawal checks.

Quick Links to Explore