1import java.util.Scanner;
2
3public class AtmSimulator {
4 public static void main(String[] args) {
5 Scanner scanner = new Scanner(System.in);
6 double balance = 25000.0;
7 final int CORRECT_PIN = 7890;
8 int attempts = 0;
9 boolean authenticated = false;
10
11 System.out.println("==========================================");
12 System.out.println(" MSK INSTITUTE DIGITAL BANKING ATM ");
13 System.out.println("==========================================");
14
15 // PIN Authentication Loop (Max 3 attempts)
16 while (attempts < 3) {
17 System.out.print("Enter your 4-digit PIN: ");
18 int pin = scanner.nextInt();
19
20 if (pin == CORRECT_PIN) {
21 authenticated = true;
22 break;
23 } else {
24 attempts++;
25 System.out.printf("Incorrect PIN. Attempts remaining: %d%n", (3 - attempts));
26 }
27 }
28
29 if (!authenticated) {
30 System.out.println("🚨 Card blocked due to 3 failed attempts. Contact support.");
31 scanner.close();
32 return;
33 }
34
35 boolean active = true;
36 while (active) {
37 System.out.println("\n---------------- ATM MENU ----------------");
38 System.out.println("1. Check Account Balance");
39 System.out.println("2. Deposit Cash");
40 System.out.println("3. Withdraw Cash");
41 System.out.println("4. Exit");
42 System.out.print("Select an option (1-4): ");
43
44 int choice = scanner.nextInt();
45
46 switch (choice) {
47 case 1 -> System.out.printf("Current Balance: ₹%,.2f%n", balance);
48 case 2 -> {
49 System.out.print("Enter deposit amount: ₹");
50 double deposit = scanner.nextDouble();
51 if (deposit > 0) {
52 balance += deposit;
53 System.out.printf("Deposited ₹%,.2f. New Balance: ₹%,.2f%n", deposit, balance);
54 } else {
55 System.out.println("Invalid deposit amount.");
56 }
57 }
58 case 3 -> {
59 System.out.print("Enter withdrawal amount: ₹");
60 double withdraw = scanner.nextDouble();
61 if (withdraw > balance) {
62 System.out.println("[ERROR]: Insufficient account balance.");
63 } else if (withdraw <= 0) {
64 System.out.println("Invalid withdrawal amount.");
65 } else {
66 balance -= withdraw;
67 System.out.printf("Please collect your cash: ₹%,.2f. Remaining: ₹%,.2f%n", withdraw, balance);
68 }
69 }
70 case 4 -> {
71 System.out.println("Please collect your card. Thank you for banking with MSK!");
72 active = false;
73 }
74 default -> System.out.println("Invalid selection. Choose 1 through 4.");
75 }
76 }
77
78 scanner.close();
79 }
80}