-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations in Bank
More file actions
644 lines (581 loc) · 18.7 KB
/
Operations in Bank
File metadata and controls
644 lines (581 loc) · 18.7 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
import java.util.Scanner;
class Account { //node class for storing data
int Account_No;
String Name;
String Address;
float Balance;
Account next;
Account(String nm ,String ad, int acc_no,float balance){ //constructor for accepting and storing data
Account_No = acc_no;
Name = nm;
Address = ad;
Balance = balance;
next = null;
}
}
class Bank{
Account head;
Scanner sc = new Scanner(System.in);
void accept() { //creating accept function for creating list
Account ptr;
int ans=0;
do {
System.out.println("Enter the account number: ");
int acc_no = sc.nextInt();
System.out.println("Enter the name of account holder: ");
String nm = sc.next();
System.out.println("Enter the adress of account holder: ");
String ad = sc.next();
System.out.println("Enter balance in the account: ");
float balance = sc.nextFloat();
System.out.println();
Account temp = new Account(nm,ad,acc_no,balance); //passing details
System.out.println("Do you want to add another node?? Press 1 if yes or else 0 : ");
ans = sc.nextInt();
temp.next=null;
if (head==null) { // condition for storing data in first node
head = temp;
}
else //data will be stored in node next to first node
{
ptr = head;
while(ptr.next!=null)
{
ptr = ptr.next;
}
ptr.next = temp;
}
} while(ans==1);
}
void insert() { //creating insert function to add node at the end of list
System.out.println("***Enter the data for node to be inserted***");
System.out.println("Enter the account number: ");
int acc_no = sc.nextInt();
System.out.println("Enter the name of account holder: ");
String nm = sc.next();
System.out.println("Enter the adress of account holder: ");
String ad = sc.next();
System.out.println("Enter balance in the account: ");
float balance = sc.nextFloat();
System.out.println();
Account temp = new Account(nm,ad,acc_no,balance); //passing details
if(head==null) { //first node
head = temp;
}
else {
Account start = head;
while(start.next!=null) { // traversing till last node coz we have to insert at last node
start=start.next;
}
start.next=temp;
}
System.out.println("The data is Inserted!!");
}
void insertAtStart() { //creating function to insert node at start of list
System.out.println("**Enter the data of node you want to insert at Start**");
System.out.println("Enter the account number: ");
int acc_no = sc.nextInt();
System.out.println("Enter the name of account holder: ");
String nm = sc.next();
System.out.println("Enter the adress of account holder: ");
String ad = sc.next();
System.out.println("Enter balance in the account: ");
float balance = sc.nextFloat();
Account temp = new Account(nm,ad,acc_no,balance);
temp.next=null; //this new node will point to null
temp.next=head; // this new node will point to initial head
head=temp; //head will point to the temp node
System.out.println("The data is inserted at strart!!");
}
void insertAtindex(int index) { //creating function to insert node at given index by passing index as parameter
int ind;
System.out.println("Enter the index where you want to insert:");
ind = sc.nextInt();
if(ind==0) //if entered index is 0 it will call insertAtStart() function
insertAtStart();
else {
if (ind<0) { //if entered index is negative which is invalid
System.out.println("Invalid Index!!");
}
else {
Account node = head; //node points to head
for (int i = 0; i < ind - 1; i++) //using for loop to reach at the required index
{
node = node.next; //points to next node
System.out.println("**Enter the data of node you want to insert at given index**");
System.out.println("Enter the account number: ");
int acc_no = sc.nextInt();
System.out.println("Enter the name of account holder: ");
String nm = sc.next();
System.out.println("Enter the adress of account holder: ");
String ad = sc.next();
System.out.println("Enter balance in the account: ");
float balance = sc.nextFloat();
Account temp = new Account(nm,ad,acc_no,balance);
temp.next=null;
temp.next=node.next;
node.next=temp;
System.out.println("The data is inserted at index : "+ind);
}
}
}
}
void delete(int index) { //creating function to delete a specific node
if (head==null) { //condition for empty list
System.out.println("Empty List");
}
else {
if(index==0) { // deleting head
head=head.next;
}
else {
Account ptr=head; // ptr pointing towards head
Account ptr1=null; // temporary node ptr1
for(int i=0;i<index-1;i++) // using for loop we can find the node before the node which is to be deleted
ptr=ptr.next;
ptr1=ptr.next;
ptr.next=ptr1.next;
}
System.out.println("Deleted Successfully!!");
}
}
void display() { //creating display function to display all nodes
Account ptr = head; //ptr pointing to head
if(head==null) {
System.out.println("Empty List");
}
else
{
int i=1;
while(ptr.next!=null) { //traversing through list
System.out.println("**Details of Account holder**");
System.out.println("Name of the account holder: " +ptr.Name);
System.out.println("Address of the account holder: " +ptr.Address);
System.out.println("Account Number: "+ptr.Account_No);
System.out.println("Balance in the account: " +ptr.Balance);
ptr=ptr.next;
i++;
System.out.println();
}
System.out.println("**Details of Account holder**"); //printing last node
System.out.println("Name of the account holder: " +ptr.Name);
System.out.println("Address of the account holder: " +ptr.Address);
System.out.println("Account Number: "+ptr.Account_No);
System.out.println("Balance in the account: " +ptr.Balance);
System.out.println();
}
}
void deposit() {
if (head == null) //condition for empty list
System.out.println("List is empty!");
else
{
Account node = head;
System.out.println("Enter the account number in which you want to deposit: ");
int acc_no = sc.nextInt();
while (node.Account_No != acc_no) //traversing through list to find the account number
{
node = node.next;
if (node == null) //if account having entered account number not found
{
System.out.println("Account having account number " +acc_no+ " not found!!");
return;
}
}
System.out.println("Enter the amount you want to deposit? ");
float balance = sc.nextFloat();
node.Balance = node.Balance + balance; //Depositing money
System.out.println("Deposited successfully!!");
}
}
void withdraw() {
if (head == null) //condition for empty list
System.out.println("List is empty!");
else
{
Account node = head;
System.out.println("Enter the account number from which you want to withdraw: ");
int acc_no = sc.nextInt();
while (node.Account_No != acc_no) //traversing through list to find the account number
{
node = node.next;
if (node == null) //if account having entered account number not found
{
System.out.println("Account having account number " +acc_no+ " not found!!");
return;
}
}
System.out.println("Enter the amount you want to deposit? ");
float balance = sc.nextFloat();
if(node.Balance-balance<1000) { //condition for withdrawing money
System.out.println("You cannot withdraw money because of insufficient Balance!!");
}
else {
node.Balance = node.Balance - balance; //withdrawing money
System.out.println("Withdrawn successfully!!");
}
}
}
}
public class Bank_Application {
public static void main(String[] args) {
// TODO Auto-generated method stub
Bank l = new Bank();
int choice;
Scanner sc = new Scanner(System.in);
do{
System.out.println("Which banking operation you want to perform:");
System.out.println("1.Accept a list of account holders: ");
System.out.println("2.Delete the data of any account holder ");
System.out.println("3.Insert the data at the start of list: ");
System.out.println("4.Insert the data at a particular index in list: ");
System.out.println("5.Insert the data at the end of list: ");
System.out.println("6.Display the list: ");
System.out.println("7.Deposit money in desired account:");
System.out.println("8.Withdraw money from desired account: ");
System.out.println();
System.out.println("Enter your choice: ");
System.out.println();
choice=sc.nextInt();
switch (choice)
{
case 1:
l.accept();
break;
case 2:
System.out.println("Enter index at which you want to delete a node: ");
int index=sc.nextInt();
l.delete(index);
break;
case 3:
l.insertAtStart();
break;
case 4:
System.out.println("Enter index at which you want to insert a node: ");
index=sc.nextInt();
l.insertAtindex( index);
break;
case 5:
l.insert();
break;
case 6:
l.display();
break;
case 7:
l.deposit();
break;
case 8:
l.withdraw();
break;
default:
System.out.println("Invalid choice!!!");
}
System.out.println();
System.out.println("If you want to continue press 1 or else 0 : ");
choice=sc.nextInt();
}
while (choice==1);
System.out.println("***Bank is Closed***");
}
}
/* OUTPUT:
* Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
1
Enter the account number:
1
Enter the name of account holder:
mitali
Enter the adress of account holder:
abc
Enter balance in the account:
4444
Do you want to add another node?? Press 1 if yes or else 0 :
1
Enter the account number:
2
Enter the name of account holder:
anjali
Enter the adress of account holder:
xyz
Enter balance in the account:
222
Do you want to add another node?? Press 1 if yes or else 0 :
0
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
6
**Details of Account holder**
Name of the account holder: mitali
Address of the account holder: abc
Account Number: 1
Balance in the account: 4444.0
**Details of Account holder**
Name of the account holder: anjali
Address of the account holder: xyz
Account Number: 2
Balance in the account: 222.0
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
2
Enter index at which you want to delete a node:
1
Deleted Successfully!!
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
6
**Details of Account holder**
Name of the account holder: mitali
Address of the account holder: abc
Account Number: 1
Balance in the account: 4444.0
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
3
**Enter the data of node you want to insert at Start**
Enter the account number:
3
Enter the name of account holder:
sakshi
Enter the adress of account holder:
wer
Enter balance in the account:
7869
The data is inserted at strart!!
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
4
Enter index at which you want to insert a node:
2
Enter the index where you want to insert:
2
**Enter the data of node you want to insert at given index**
Enter the account number:
34
Enter the name of account holder:
rutuja
Enter the adress of account holder:
yui
Enter balance in the account:
4532
The data is inserted at index : 2
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
5
***Enter the data for node to be inserted***
Enter the account number:
53
Enter the name of account holder:
madhura
Enter the adress of account holder:
fgh
Enter balance in the account:
5555
The data is Inserted!!
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
6
**Details of Account holder**
Name of the account holder: sakshi
Address of the account holder: wer
Account Number: 3
Balance in the account: 7869.0
**Details of Account holder**
Name of the account holder: mitali
Address of the account holder: abc
Account Number: 1
Balance in the account: 4444.0
**Details of Account holder**
Name of the account holder: rutuja
Address of the account holder: yui
Account Number: 34
Balance in the account: 4532.0
**Details of Account holder**
Name of the account holder: madhura
Address of the account holder: fgh
Account Number: 53
Balance in the account: 5555.0
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
7
Enter the account number in which you want to deposit:
34
Enter the amount you want to deposit?
500
Deposited successfully!!
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
6
**Details of Account holder**
Name of the account holder: sakshi
Address of the account holder: wer
Account Number: 3
Balance in the account: 7869.0
**Details of Account holder**
Name of the account holder: mitali
Address of the account holder: abc
Account Number: 1
Balance in the account: 4444.0
**Details of Account holder**
Name of the account holder: rutuja
Address of the account holder: yui
Account Number: 34
Balance in the account: 5032.0
**Details of Account holder**
Name of the account holder: madhura
Address of the account holder: fgh
Account Number: 53
Balance in the account: 5555.0
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
8
Enter the account number from which you want to withdraw:
1
Enter the amount you want to deposit?
1111
Withdrawn successfully!!
If you want to continue press 1 or else 0 :
1
Which banking operation you want to perform:
1.Accept a list of account holders:
2.Delete the data of any account holder
3.Insert the data at the start of list:
4.Insert the data at a particular index in list:
5.Insert the data at the end of list:
6.Display the list:
7.Deposit money in desired account:
8.Withdraw money from desired account:
Enter your choice:
6
**Details of Account holder**
Name of the account holder: sakshi
Address of the account holder: wer
Account Number: 3
Balance in the account: 7869.0
**Details of Account holder**
Name of the account holder: mitali
Address of the account holder: abc
Account Number: 1
Balance in the account: 3333.0
**Details of Account holder**
Name of the account holder: rutuja
Address of the account holder: yui
Account Number: 34
Balance in the account: 5032.0
**Details of Account holder**
Name of the account holder: madhura
Address of the account holder: fgh
Account Number: 53
Balance in the account: 5555.0
If you want to continue press 1 or else 0 :
0
***Bank is Closed***
*/