-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM.java
More file actions
91 lines (66 loc) · 2.65 KB
/
Copy pathATM.java
File metadata and controls
91 lines (66 loc) · 2.65 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
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.*;
public class ATM{
static int balance = 1_00_000;
static int PIN = 6340;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("=====Welcome to the ATM system====");
int counter = 0;
while(counter!=3){
System.out.print("Enter the PIN : ");
int pin = sc.nextInt();
if(pin==PIN){
System.out.println("The PIN is correct ! Welcome ");
while(true){
System.out.println("1. Check Balance : ");
System.out.println("2. Deposit Money : ");
System.out.println("3. Withdraw Money : ");
System.out.println("4. Exit : ");
int choice = sc.nextInt();
switch (choice){
case 1 -> checkBalance();
case 2 -> depositMoney (sc);
case 3 -> withdrawMoney(sc);
case 4 ->{
System.out.println("Thank you for trusting us as banking \n BYE!...");
return; }
default->
System.out.println("Invalid choice please select another one ");
}
}
}
else{
System.out.println("The PIN is incorrect ! Try again please ....");
}
counter++;
}
if(counter==3){
System.out.println("Your ATM has been blocked due to multiple wrong PIN attempts ");
}
}
public static void checkBalance(){
System.out.println("The balance is " + balance);
}
public static void withdrawMoney(Scanner sc){
System.out.print("Enter the amount you want to withdraw : ");
int withdraw = sc.nextInt();
if(balance>0 && withdraw<=balance){
balance-=withdraw;
System.out.println("The balancee is " + balance);
}
else{
System.out.println("The balance is insufficient ");
}
}
public static void depositMoney(Scanner sc){
System.out.print("Enter the amout you want to deposit : ");
int deposit = sc.nextInt();
if(deposit>0){
balance+=deposit;
System.out.println("The balance is " + balance);
}
else{
System.out.println("Invalid amount ");
}
}
}