-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMExample.java
More file actions
79 lines (63 loc) · 2.39 KB
/
Copy pathATMExample.java
File metadata and controls
79 lines (63 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.Scanner;
public class ATMExample {
public static void main(String[] args) {
int balance = 100000, withdraw, deposit;
Scanner sc = new Scanner(System.in);
int pin = 1234;
int enteredPin;
int attempts = 0;
while (true) {
System.out.print("Enter your ATM PIN: ");
enteredPin = sc.nextInt();
if (enteredPin == pin) {
System.out.println("access granted\n");
break;
} else {
attempts++;
System.out.println("incorrect PIN");
if (attempts == 3) {
System.out.println("Too many failed attempts.");
System.exit(0);
}
}
}
while (true) {
System.out.println("===== Automated Teller Machine =====");
System.out.println("1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter money to withdraw: ");
withdraw = sc.nextInt();
if (balance >= withdraw) {
balance = balance - withdraw;
System.out.println("Please collect your money");
} else {
System.out.println("nsufficient Balance");
}
System.out.println();
break;
case 2:
System.out.print("Enter money to deposit: ");
deposit = sc.nextInt();
balance = balance + deposit;
System.out.println("Money deposited successfully");
System.out.println();
break;
case 3:
System.out.println("Balance: " + balance);
System.out.println();
break;
case 4:
System.out.println("Thank you for using ATM!");
System.exit(0);
default:
System.out.println("nvalid Choice\n");
}
}
}
}