-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMinterface_BankIndia.java
More file actions
323 lines (268 loc) · 14.2 KB
/
Copy pathATMinterface_BankIndia.java
File metadata and controls
323 lines (268 loc) · 14.2 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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import java.util.Scanner;
class Bank_Account {
String accholdername;
String username;
String password;
String accno;
String acctype;
int transactions = 0;
String transactionHistory = "";
double balance;
double overdraft;
public void register() {
Scanner s = new Scanner(System.in);
System.out.println("\n═══════════════════════════════════════");
System.out.println(" Welcome to the Northern Bank");
System.out.println("═══════════════════════════════════════\n");
System.out.print("Enter the Account holder's name: ");
this.accholdername = s.nextLine();
System.out.print("Enter your username: ");
this.username = s.nextLine();
System.out.print("Enter your password: ");
this.password = s.nextLine();
System.out.print("Enter the Account Number: ");
this.accno = s.nextLine();
System.out.print("Enter the Account Type(Current or Savings): ");
this.acctype = s.nextLine();
System.out.print("Enter initial deposite: ");
this.balance = s.nextDouble();
System.out.println("\n Registration Successful!\n");
System.out.println("Please log in to your bank account\n");
}
public boolean login() {
boolean islogin = false;
Scanner s = new Scanner(System.in);
while (!islogin) {
System.out.print("Enter your username: ");
String user = s.nextLine();
if (user.equals(username)) {
System.out.print("Enter your password: ");
String pass = s.nextLine();
if (pass.equals(password)) {
System.out.println("\n Login Successful!\n");
islogin = true;
} else {
System.out.println(" Incorrect password! Try again.\n");
}
} else {
System.out.println(" Incorrect username! Try again.\n");
}
}
return islogin;
}
public void deposite() {
System.out.println("\n═══════════════════════════════════════");
System.out.println(" DEPOSIT");
System.out.println("═══════════════════════════════════════");
System.out.print("Enter Amount to Deposit: Rs.");
Scanner s = new Scanner(System.in);
double amount = s.nextDouble();
try {
if (amount >= 100.00) {
transactions++;
balance = balance + amount;
System.out.println("\n Transaction Successful!");
System.out.println("Amount Deposited: Rs." + amount);
System.out.println("Current Balance: Rs." + balance + "\n");
String str = transactions + ". Rs." + amount + " deposited\n";
transactionHistory = transactionHistory.concat(str);
} else {
System.out.println("\n Sorry. Minimum deposit amount is Rs.100.00\n");
}
} catch (Exception e) {
System.out.println("\n Invalid input!\n");
}
}
public void withdraw() {
System.out.println("\n═══════════════════════════════════════");
System.out.println(" WITHDRAWAL");
System.out.println("═══════════════════════════════════════");
System.out.print("Enter Amount to Withdraw: Rs.");
Scanner s = new Scanner(System.in);
double amount = s.nextDouble();
if(acctype.equals("Savings")){
try {
if (balance >= amount) {
transactions++;
balance = balance - amount;
System.out.println("\n Transaction Successful!\n");
System.out.println("Amount Withdrawn: Rs." + amount);
System.out.println("Current Balance: Rs." + balance + "\n");
String str = transactions + ". Rs." + amount + " withdrawn\n";
transactionHistory = transactionHistory.concat(str);
} else {
System.out.println("\n Insufficient Balance\n");
}
} catch (Exception e) {
System.out.println("\n Invalid input!\n");
}
}
else{
try {
if (balance >= amount) {
transactions++;
balance = balance - amount;
System.out.println("\n Transaction Successful!");
System.out.println("Amount Withdrawn: Rs." + amount);
System.out.println("Current Balance: Rs." + balance + "\n");
String str = transactions + ". Rs." + amount + " withdrawn\n";
transactionHistory = transactionHistory.concat(str);
}
else if(balance<amount && amount<=50000){
transactions++;
balance = balance - amount;
overdraft =0- balance;
System.out.println("\n Transaction Successful!");
System.out.println("Amount Withdrawn: Rs." + amount+"\n");
System.out.println("Current Balance: Rs." + balance);
System.out.println("Overdrafted amount: Rs."+overdraft+"\n");
String str = transactions + ". Rs." + amount + " withdrawn and Rs."+overdraft+" Overdrafted\n";
transactionHistory = transactionHistory.concat(str);
}
else {
System.out.println("\n Overdraft limit exceeded!\n");
}
} catch (Exception e) {
System.out.println("\n Invalid input!\n");
}
}
}
public void transfer() {
System.out.println("\n═══════════════════════════════════════");
System.out.println(" TRANSFER");
System.out.println("═══════════════════════════════════════");
System.out.print("Enter Recipient's name: ");
Scanner s = new Scanner(System.in);
String recipient = s.nextLine();
System.out.print("Enter amount to transfer: Rs.");
double amount = s.nextDouble();
try {
if (balance >= amount) {
if (amount <= 50000.00) {
transactions++;
balance = balance - amount;
System.out.println("\n Transaction Successful!");
System.out.println("Amount Transferred: Rs." + amount);
System.out.println("Recipient: " + recipient);
System.out.println("Current Balance: Rs." + balance + "\n");
String str = transactions + ". Rs." + amount + " transferred to " + recipient + "\n";
transactionHistory = transactionHistory.concat(str);
} else {
System.out.println("\n Transaction maximum amount limit is Rs.50,000.00\n");
}
} else {
System.out.println("\n Insufficient Balance\n");
}
} catch (Exception e) {
System.out.println("\n Invalid input!\n");
}
}
public void check_balance() {
System.out.println("\n═══════════════════════════════════════");
System.out.println(" BALANCE INQUIRY");
System.out.println("═══════════════════════════════════════");
System.out.println("Account Holder: " + accholdername);
System.out.println("Account Number: " + accno);
System.out.println("Current Balance: Rs." + balance + "\n");
}
public void transaction_history() {
System.out.println("\n═══════════════════════════════════════");
System.out.println(" TRANSACTION HISTORY");
System.out.println("═══════════════════════════════════════");
if (transactions == 0) {
System.out.println("No Previous Transactions.\n");
} else {
System.out.println(transactionHistory);
System.out.println("Total Transactions: " + transactions + "\n");
}
}
}
public class ATMinterface_BankIndia {
public static int takenIntegerInput(int limit) {
int input = 0;
boolean flag = false;
while (!flag) {
try {
Scanner s = new Scanner(System.in);
input = s.nextInt();
flag = true;
if (flag && (input > limit || input < 1)) {
System.out.println(" Choose a number between 1 to " + limit);
flag = false;
}
} catch (Exception e) {
System.out.println(" Enter only integer value.");
flag = false;
}
}
return input;
}
public static void main(String args[]) {
System.out.println("\n╔═══════════════════════════════════════════════════════════════╗");
System.out.println("║ Welcome to Bank of India ATM Interface ║");
System.out.println("╚═══════════════════════════════════════════════════════════════╝\n");
System.out.println("1. Register");
System.out.println("2. Exit");
System.out.print("\nChoose one option: ");
int choose = takenIntegerInput(2);
if (choose == 1) {
Bank_Account bacc = new Bank_Account();
bacc.register();
while (true) {
System.out.println("1. Login");
System.out.println("2. Exit");
System.out.print("\nEnter your choice: ");
int ch = takenIntegerInput(2);
if (ch == 1) {
if (bacc.login()) {
System.out.println("╔═══════════════════════════════════════════════════════════════╗");
System.out.println("║ Welcome Back " + bacc.accholdername + "!"+ "║");
System.out.println("╚═══════════════════════════════════════════════════════════════╝");
boolean isFinished = false;
while (!isFinished) {
System.out.println("\n─────────────────────────────────────");
System.out.println(" MAIN MENU");
System.out.println("─────────────────────────────────────");
System.out.println("1. Withdrawal");
System.out.println("2. Deposit");
System.out.println("3. Transfer");
System.out.println("4. Check Balance");
System.out.println("5. Transaction History");
System.out.println("6. Exit");
System.out.print("\nEnter your choice: ");
int choice = takenIntegerInput(6);
switch (choice) {
case 1:
bacc.withdraw();
break;
case 2:
bacc.deposite();
break;
case 3:
bacc.transfer();
break;
case 4:
bacc.check_balance();
break;
case 5:
bacc.transaction_history();
break;
case 6:
isFinished = true;
System.out.println("\n Thank you for using Bank of India ATM!");
System.out.println("Have a great day!\n");
break;
}
}
}
} else {
System.out.println("\n Thank you for visiting Bank of India!");
System.exit(0);
}
}
} else {
System.out.println("\n Thank you for visiting Bank of India!");
System.exit(0);
}
}
}