1package JavaProjects;
2
3import java.util.Scanner;
4
5public class JavaProjects {
6
7 public static void main(String[] args) {
8 System.out.println("Welcome to Sujan ATM\n");
9
10 Scanner sc = new Scanner(System.in);
11
12 // Account details
13 double accountNumber = 123456;
14 int pinCode = 0000;
15 double accountBalance = 500;
16
17 int attempts = 0;
18
19 while (attempts < 3) {
20 System.out.print("Enter your bank account number: ");
21 double userAccountNumber = sc.nextDouble();
22
23 System.out.print("Enter your security PIN code: ");
24 int userPinCode = sc.nextInt();
25
26 if (userAccountNumber == accountNumber && userPinCode == pinCode) {
27 performAccountAction(sc, accountBalance);
28 break;
29 } else {
30 attempts++;
31 System.out.println("\nIncorrect account number or PIN code\n");
32 }
33 }
34
35 if (attempts == 3) {
36 System.out.println("Maximum attempts reached. Please try again later.");
37 }
38 }
39
40 public static void performAccountAction(Scanner sc, double accountBalance) {
41 int userAction;
42 do {
43 accountAction();
44 System.out.print("Enter your choice: ");
45 userAction = sc.nextInt();
46
47 switch (userAction) {
48 case 1:
49 System.out.println("Your current account balance is: $" + accountBalance);
50 break;
51
52 case 2:
53 System.out.print("Enter amount to deposit: $");
54 double depositAmount = sc.nextDouble();
55 accountBalance += depositAmount;
56 System.out.println("Deposit successful. Your updated balance is: $" + accountBalance);
57 break;
58
59 case 3:
60 System.out.print("Enter amount to withdraw: $");
61 double withdrawAmount = sc.nextDouble();
62 if (withdrawAmount > accountBalance) {
63 System.out.println("Sorry ! Insufficient funds.");
64 } else {
65 accountBalance -= withdrawAmount;
66 System.out.println("Withdrawal successful. Your new balance is: $" + accountBalance);
67 }
68 break;
69
70 case 4:
71 System.out.println("Thank you for using Commonwealth Bank ATM!");
72 break;
73
74 default:
75 System.out.println("Invalid selection.");
76 break;
77 }
78 if (userAction != 4) {
79 System.out.println("Do you want to perform another action? (yes/no): ");
80 String choice = sc.next();
81 if (choice.equalsIgnoreCase("no")) {
82
83 System.out.print("\nThank you for using Sujan ATM. See you next time !");
84 return;
85 }
86 }
87
88 } while (userAction != 4);
89 }
90
91 public static void accountAction() {
92 System.out.println("\nPlease select from the following options:\n" + "1. Check Account Balance\n"
93 + "2. Deposit\n" + "3. Withdraw\n" + "4. Exit");
94 }
95}▍