-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM Interface
255 lines (241 loc) · 5.54 KB
/
ATM Interface
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package online_reservation_system;
import java.util.*;
class BankAccount
{
String name;
String userName;
String password;
String accountNo;
float balance = 100000f;
int transactions = 0;
String transactionHistory ="";
public void register()
{
Scanner sc = new Scanner(System.in);
System.out.print ("\nEnter Your Name - ");
this.name = sc.nextLine();
System.out.print ("\nEnter Your Username - ");
this.userName = sc.nextLine();
System.out.print ("\nEnter Your Password - ");
this.password = sc.nextLine();
System.out.print ("\nEnter Your Account Number - ");
this.accountNo = sc.nextLine();
System.out.print ("\nRegistration completed..Kindly Login");
}
public boolean login()
{
boolean isLogin = false;
Scanner sc = new Scanner (System.in);
while (!isLogin)
{
System.out.print("\nEnter Your Username - ");
String Username = sc.nextLine();
if(Username.equals(Username))
{
while ( !isLogin)
{
System.out.print("\nEnter Your Password - ");
String Password = sc.nextLine();
if (Password.equals (password))
{
System.out.println("\nLogin successful!!");
isLogin = true;
}
else
{
System.out.println("\nIcorrect Password");
}
}
}
else
{
System.out.println("\nUsername not found");
}
}
return isLogin;
}
public void withdraw()
{
System.out.print ("\nEnter amount to withdraw - ");
Scanner sc = new Scanner(System.in);
float amount = sc.nextFloat ();
try
{
if (balance >= amount)
{
transactions++;
balance = amount;
System.out.println("\nWithdraw Successfully");
String str = amount + "Rs Withdrawed\n";
transactionHistory = transactionHistory.concat(str);
}
else {
System.out.println("Insufficient Balance");
}
}
catch (Execption e)
{
System.out.println("Transaction Not complete");
}
}
public void deposit ()
{
System.out.print ("\nEnter amount to deposit ");
Scanner sc = new Scanner(System.in);
float amount = sc.nextFloat();
try
{
if ( amount <= 100000f)
{
transactions++;
balance += amount;
System.out.println("\nSuccessfully Deposited");
String str = amount + " Rs deposited\n";
transactionHistory = transactionHistory.concat (str);
}
else
{
System.out.println("\nSorry...Limit is 100000.00");
}
}
catch(Exception e)
{
}
}
public void transfer()
{
Scanner sc = new Scanner(System.in);
System.out.print("\n Enter Receipent's Name - ");
String receipent = sc.nextLine();
System.out.print("\nEnter amount to transfer - ");
float amount = sc.nextFloat();
try
{
if (balance >= amount)
{
if(amount <= 50000f)
{
transactions++;
balance -= amount;
System.out.println("\nSuccessfully Transfered to " + receipent);
String str = amount + "Rs transfered to " + receipent + "\n";
transactionHistory = transactionHistory.concat(str);
}
else
{
System.out.println("\n Sorry limit is 50000.00");
}
}
else
{
System.out.println("\nInsufficient Balance");
}
}
catch(Exception e)
{
}
}
public void checkBalance()
{
System.out.println("\n" + balance + "Rn");
}
public void transactionHistory()
{
if(transactions == 0)
{
System.out.println("\nEmpty");
}
else
{
System.out.println("\n" + transactionHistory);
}
}
}
public class AtmInterface
{
public static int takeIntegerInput(int limit)
{
int input = 0;
boolean flag = false;
while ( !flag )
{
try
{
Scanner sc = new Scanner(System.in);
input = sc.nextInt();
flag = true;
if (flag && input > limit || input <1)
{
System.out.println("Choose the number between 1 to " + limit);
}
}
catch(Exception e)
{
System.out.println("Enter only integer value");
flag = false;
}
};
return input;
}
public static void main(String[] args)
{
System.out.println("\n******WELCOME TO THE BANK ATM SYSTEM********\n ");
System.out.println("1. Register \n2.EXIT");
System.out.println("Enter Your Choice - ");
int choice = takeIntegerInput(2);
if (choice == 1)
{
BankAccount b = new BankAccount();
b.register();
while(true)
{
System.out.println("\n1.Login \n2.EXIT");
System.out.println("Enter Your choice - ");
int ch = takeIntegerInput(2);
if(ch == 1)
{
if(b.login())
{
System.out.println("\n\n***********WELCOME BACK " + b.name + "***********\n");
boolean isFinished = false;
while(!isFinished)
{
System.out.println("\n1.Withdraw \n2.Deposit \n3.Transfer \n4.Check Balance \n5.Transaction History \n6.EXIT");
System.out.println("\nEnter Your Choice");
int c = takeIntegerInput(6);
switch(c)
{
case 1:
b.withdraw();
break;
case 2:
b.deposit();
break;
case 3:
b.transfer();
break;
case 4:
b.checkBalance();
break;
case 5:
b.transactionHistory();
break;
case 6:
isFinished = true;
break;
}
}
}
}
else
{
System.exit(0);
}
}
}
else
{
System.exit(0);
}
}
}