-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm.java
124 lines (117 loc) · 3.27 KB
/
atm.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.Scanner;
class Atm
{
static int i=0;
static int j=0;
int balance=20000;
String s1[]=new String[]{"123","456","789","987","654","321","147","258","369","777"};
void mainMenu()
{
System.out.println(" *********************");
System.out.println(" WELCOME ");
System.out.println(" TO AXIS BANK ");
System.out.println(" *********************");
getPassword();
}
void getPassword()
{
char s2[]=System.console().readPassword(" Sir pls Enter your pin-");
String s3=new String(s2);
comparePassword(s3);
}
void comparePassword(String s3)
{
if(i<2)
{
int x=0;
for(int i=0;i<10;i++)
{
if(s3.equals(s1[i]))
{
x=1;
withdrawMoney(s3);
break;
}
else
continue;
}
if(x==0)
{
i++;
System.out.println(" SORRY!!!!!! INVALID PASSWORD");
System.out.println(" Please Enter your password again");
getPassword();
}
}
else
{
System.out.println(" !!!!!!!!!!! LIMIT EXCEEDED !!!!!!!!!!!!!!!!!!!" );
System.out.println(" YOU HAVE ENTERED WRONG PW FOR 3 TIMES");
System.out.println(" ************THANK YOU SIR FOR USING AXIS BANK************");
System.out.println(" ======================================================================");
}
}
void withdrawMoney(String s3)
{
System.out.println(" YOUR CURRENT BALANCE IS "+balance);
Scanner sc=new Scanner(System.in);
System.out.println(" Enter how much money you withdraw-");
int amt=sc.nextInt();
if(amt<=balance)
{
System.out.println(" Your account is debited with "+amt);
int newbalance=balance-amt;
balance=newbalance;
System.out.println(" You current balance is-"+balance);
withdrawMoreMoney(balance,s3);
}
else
{
System.out.println(" SORRY!!!!! YOU HAVE NOT SUFFICIENT MONEY TO WITHDRAW..........");
withdrawMoney(s3);
}
}
void withdrawMoreMoney(int balance,String s3)
{
Scanner sc=new Scanner(System.in);
System.out.println(" ***Would YOU like to withdraw more MONEY***");
System.out.println(" yes or no");
String s4="yes";
String s5="no";
String s6=sc.next();
if(s6.equals(s4))
{
recheckPassword(s3);
}
else
{
System.out.println(" ***THANK YOU SIR FOR USING AXIS BANK****");
System.out.println("================================================================================");
}
}
void recheckPassword(String s3)
{ if(j<3)
{
char s7[]=System.console().readPassword(" Sir pls Enter your pin-");
String s8=new String(s7);
if(s8.equals(s3))
withdrawMoney(s3);
else
{
System.out.println(" ########### WARNING ###########");
System.out.println(" WRONG PASSWORD");
j++;
recheckPassword(s3);
}
}
else{
System.out.println(" !!!!!!!!! OOPSS!!!!!!! SORRY !!!!!");
System.out.println(" INVALID PASSWORD. MAXIMUM ATTEMPTS EXCEEDED.");
}
}
public static void main(String ... args)
{
Atm a=new Atm();
a.mainMenu();
}
}