-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathBanking_management_system.java
277 lines (254 loc) · 8.73 KB
/
Banking_management_system.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
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
import java.util.Scanner;
class Account {
private int accountNumber;
private String accountType;
private String serviceBranchIFSC;
private float minimumBalance;
private float availableBalance;
private int coustomerID;
private String coustmerName;
private static int totalAccountCreated;
Account() {
accountNumber = 0;
accountType = "";
serviceBranchIFSC = "";
minimumBalance = 0;
availableBalance = 0;
coustomerID = 0;
coustmerName = "";
totalAccountCreated++;
}
public void setDetails(
int accnumber,
String acctype,
String IFSC,
float minBalance,
float avaBalance,
int coustID,
String coustName
) {
accountNumber = accnumber;
accountType = acctype;
serviceBranchIFSC = IFSC;
minimumBalance = minBalance;
availableBalance = avaBalance;
coustomerID = coustID;
coustmerName = coustName;
}
public String getDetails(int BankId) {
return ("\nAccount number: " +accountNumber +"\nAccount type: " +accountType +"\nIFSC code: " +serviceBranchIFSC +"\nMin Balance: " +minimumBalance +"\nAvailable Balance: " +availableBalance +"\nCoustmer Id: " +coustomerID +"\nCoustmer name: " +coustmerName +"\n"
);
}
public float getBalance(int accoutNumber) {
return (availableBalance);
}
public void deposit(int accountNumber, float amount) {
availableBalance = availableBalance + amount;
System.out.println("Rs " +amount +" has credited in account.Balance of account is: " +availableBalance
);
}
public void withdraw(int accountNumber, float amount) {
if (amount <= availableBalance) {
availableBalance = availableBalance - amount;
System.out.println("Rs " +amount +" has withdrawn from account.Balance of account is:" +availableBalance
);
} else {
System.out.println(
"You have not enough amount in your account to withdraw."
);
}
}
static int totalAccount() {
return totalAccountCreated;
}
public int getid() {
return coustomerID;
}
public int getacno() {
return accountNumber;
}
public void updateminbalance(int accountNumber, int amount) {
minimumBalance = amount;
}
public void updatecname(int accountNumber, String name) {
coustmerName = name;
}
public void updatecid(int accountNumber, int id) {
coustomerID = id;
}
public void compare(Account first, Account second) {
if (first.availableBalance > second.availableBalance) {
System.out.print(
"\nFirst account has more balance than second.\nDetalis of first account are:"
);
String f = first.getDetails(first.getacno());
System.out.println(f);
}
if (first.availableBalance < second.availableBalance) {
System.out.print(
"\nSecond account has more balance than first.\nDetails of second account are:"
);
String s = second.getDetails(second.getacno());
System.out.println(s);
}
if (first.availableBalance == second.availableBalance) {
System.out.println("\nBoth account have same balance.");
System.out.print("Details of first account are: ");
String i = first.getDetails(first.getacno());
System.out.println(i);
System.out.print("\nDetails of second account are: ");
String ii = second.getDetails(second.getacno());
System.out.println(ii);
}
}
}
public class l4q1 {
public static void main(String[] args) {
Account[] arr;
arr = new Account[100];
for (int i = 0; i < 5; i++) {
arr[i] = new Account();
}
arr[0].setDetails(2101001, "Savings", "IIITG1234", 0, 25000, 101, "ABC");
arr[1].setDetails(2101002, "Savings", "IIITG1234", 0, 10000, 102, "MNO");
arr[2].setDetails(2101003, "Savings", "IIITG1234", 0, 100000, 103, "JKL");
arr[3].setDetails(2101004, "Savings", "IIITG1234", 0, 53000, 104, "PQR");
arr[4].setDetails(2101005, "Savings", "IIITG1234", 0, 18000, 105, "XYZ");
Scanner sc = new Scanner(System.in);
System.out.println(
"\nEnter 1 for Update Details\nEnter 2 for Get Details\nEnter 3 for Deposit\nEnter 4 for Withdraw\nEnter 5 for compare two accounts\nEnter 6 to display total no. of account created\nEnter 7 for exit."
);
int n = 1;
int flag = 0;
while (n != 7) {
int p = 5;
flag = 0;
System.out.print("\nEnter your choice:");
n = sc.nextInt();
switch (n) {
case 1:
System.out.print(
"Enter the account no. whose details you want to update:"
);
int b_id = sc.nextInt();
for (int j = 0; j < p; j++) {
if (arr[j].getacno() == b_id) {
System.out.print(
"\nEnter 1 for Update minimum balance\n2 for Get update coustmer id\n3 for update coustmer name\n\nEnter a number according to the type of change you want:"
);
int u = sc.nextInt();
String e = sc.nextLine();
if (u == 1) {
System.out.print("Enter the new minimum balance:");
int min_bal = sc.nextInt();
arr[j].updateminbalance(b_id, min_bal);
System.out.print("Minimum balance updated.");
flag = 1;
}
if (u == 2) {
System.out.print("Enter the new coustmer id:");
int id = sc.nextInt();
arr[j].updatecid(b_id, id);
System.out.print("Coustmer id updated.");
flag = 1;
}
if (u == 3) {
System.out.print("Enter the name:");
String name = sc.nextLine();
arr[j].updatecname(b_id, name);
System.out.print("Name updated.");
flag = 1;
}
if (u != 1 && u != 2 && u != 3) {
System.out.print("You entered a wrong option.Try again");
flag = 1;
}
}
}
if (flag == 0) {
System.out.print("You entered a wrong account no.Try again.");
}
break;
case 2:
flag = 0;
System.out.print("Enter the account no. whose details you want:");
int bid = sc.nextInt();
for (int j = 0; j < p; j++) {
if (arr[j].getacno() == bid) {
String b = arr[j].getDetails(bid);
System.out.print(b);
}
}
break;
case 3:
flag = 0;
System.out.print("Enter the account no:");
int id1 = sc.nextInt();
System.out.print("Enter the amount:");
int d = sc.nextInt();
for (int j = 0; j < p; j++) {
if (arr[j].getacno() == id1) {
arr[j].deposit(id1, d);
flag = 1;
break;
}
}
if (flag == 0) {
System.out.print("You entered a wrong account no.Try again.");
}
break;
case 4:
flag = 0;
System.out.print("Enter the account no:");
int id2 = sc.nextInt();
System.out.print("Enter the amount:");
int w = sc.nextInt();
for (int j = 0; j < p; j++) {
if (arr[j].getacno() == id2) {
arr[j].withdraw(id2, w);
flag = 1;
break;
}
}
if (flag == 0) {
System.out.print("You entered a wrong account no.Try again.");
}
break;
case 5:
flag = 1;
System.out.print("Enter the first account no.:");
int id3 = sc.nextInt();
String a = sc.nextLine();
System.out.print("Enter the second account no.:");
int id4 = sc.nextInt();
for (int i = 0; i < p; i++) {
for (int j = 0; j < p; j++) {
if (arr[i].getacno() == id3 && arr[j].getacno() == id4) {
arr[i].compare(arr[i], arr[j]);
flag = 1;
break;
}
}
}
if (flag == 0) {
System.out.print("You entered a wrong account no.Try again.");
}
break;
case 7:
System.out.println("Thank you for visiting us.");
break;
case 6:
System.out.println(
"Total no of account created is: " + Account.totalAccount()
);
break;
default:
System.out.println(
"The entered number does not belong to the given options.Try again."
);
break;
}
}
sc.close();
}
}