forked from ravya1108/hactoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Banking.java
321 lines (264 loc) · 11.7 KB
/
Banking.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
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
import java.util.Scanner;
class Account {
private int accountNumber;
private String accountType;
private String serviceBranchIFSC;
private float minimumBalance;
private float availableBalance;
private int customerID;
private String customerName;
private static int totalAccountCreated;
Account() {
}
public int getAccNumber() {
return accountNumber;
}
public int check_accountno(int id) {
if (id == accountNumber) {
return 1;
}
return 0;
}
public int check_customerid(int id) {
if (id == customerID) {
return 1;
}
return 0;
}
public void setDetails(int accnumber, String acctype, float minbal, String ifsc, String accholder, float balance,
int customer_Id, int totalacc) {
accountNumber = accnumber;
accountType = acctype;
minimumBalance = minbal;
serviceBranchIFSC = ifsc;
availableBalance = balance;
customerName = accholder;
customerID = customer_Id;
totalAccountCreated = totalacc;
}
public void updateDetails(int accnumber, String acctype, float minbal, String ifsc, String accholder, float balance,
int customer_Id) {
if (accountNumber == accnumber) {
accountType = acctype;
minimumBalance = minbal;
serviceBranchIFSC = ifsc;
availableBalance = balance;
customerName = accholder;
customerID = customer_Id;
}
}
public void getDetails(int accnumber) {
if (accnumber == accountNumber) {
System.out.println("------------------------------------------------------------------------------");
System.out.println("\t Account Number : " + accountNumber);
System.out.println("\t Account Type : " + accountType);
System.out.println("\t Minimum Balance : " + minimumBalance);
System.out.println("\t IFSC : " + serviceBranchIFSC);
System.out.println("\t Available Balance : " + availableBalance);
System.out.println("\t Customer Name : " + customerName);
System.out.println("\t Customer ID : " + customerID);
System.out.println("------------------------------------------------------------------------------");
}
}
public void Deposit(int accnumber, float amount) {
if (accnumber == accountNumber) {
availableBalance += amount;
System.out.println("------------------------------------------------------------------------------");
System.out.println("\tSuccesfully Deposited! For Account Number : " + accountNumber);
System.out.println("------------------------------------------------------------------------------");
}
}
public void Withdraw(int accnumber, float amount) {
if (accnumber == accountNumber) {
if (availableBalance >= amount + minimumBalance) {
availableBalance -= amount;
System.out.println("------------------------------------------------------------------------------");
System.out.println("\tSuccessfully Withdrawn! For Account Number : " + accountNumber);
System.out.println("------------------------------------------------------------------------------");
} else {
System.out.println("------------------------------------------------------------------------------");
System.out.println("\tNot much Balance!");
System.out.println("------------------------------------------------------------------------------");
}
}
}
public float getBalance(int accnumber) {
if (accnumber == accountNumber)
return availableBalance;
else {
return -1;
}
}
public static int totalAccount() {
return totalAccountCreated;
}
public void compare(Account ac1, Account ac2) {
float bal_1 = ac1.getBalance(ac1.accountNumber);
float bal_2 = ac2.getBalance(ac2.accountNumber);
if (bal_1 > bal_2) {
ac1.getDetails(ac1.accountNumber);
} else {
ac2.getDetails(ac2.accountNumber);
}
}
}
public class Banking {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Account[] arr;
arr = new Account[100];
int i = 0;
while (true) {
System.out.println("\t -------------------");
System.out.println("\t|0 - setDetails() |");
System.out.println("\t|1 - UpdateDetails()|");
System.out.println("\t|2 - getDetails() |");
System.out.println("\t|3 - Deposit() |");
System.out.println("\t|4 - Withdraw() |");
System.out.println("\t|5 - getBalance() |");
System.out.println("\t|6 - totalAccount() |");
System.out.println("\t|7 - compare() |");
System.out.println("\t|8 - Exit() |");
System.out.println("\t -------------------");
System.out.println("Enter your choice");
int choice = input.nextInt();
if (choice == 0) {
System.out.println("Enter Account details for Person " + (i + 1));
System.out.println("Enter Account Number");
int accnumber = input.nextInt();
input.nextLine();
System.out.println("Enter Account Type");
String acctype = input.nextLine();
System.out.println("Enter Minimum Balance");
float minbal = input.nextFloat();
System.out.println("Enter Customer Name");
input.nextLine();
String accholder = input.nextLine();
System.out.println("Enter Total Balance");
float balance = input.nextInt();
System.out.println("Enter IFSC Of Branch");
input.nextLine();
String ifsc = input.nextLine();
System.out.println("Enter Customer-ID Number");
int customer_Id = input.nextInt();
input.nextLine();
if (minbal > balance) {
System.out.println("Can't have balance less than minimum balance!");
} else {
int flag = 0, temp = 0;
for (int j = 0; j < i; j++) {
flag = arr[j].check_accountno(accnumber);
if (flag == 1) {
break;
}
}
for (int j = 0; j < i; j++) {
temp = arr[j].check_customerid(customer_Id);
if (temp == 1) {
break;
}
}
if (flag == 0 && temp == 0) {
arr[i] = new Account();
arr[i].setDetails(accnumber, acctype, minbal, ifsc, accholder, balance, customer_Id, i + 1);
i++;
}
else if (flag == 1) {
System.out.println("Account number already exist!");
} else if (temp == 1) {
System.out.println("Customer of same I'd already exist!");
}
}
} else if (choice == 1) {
System.out.println("Enter Account Number");
int accnumber = input.nextInt();
input.nextLine();
System.out.println("Enter Account Type");
String acctype = input.nextLine();
System.out.println("Enter Minimum Balance");
float minbal = input.nextFloat();
System.out.println("Enter Customer Name");
input.nextLine();
String accholder = input.nextLine();
System.out.println("Enter Total Balance");
float balance = input.nextInt();
System.out.println("Enter IFSC Of Branch");
input.nextLine();
String ifsc = input.nextLine();
System.out.println("Enter Customer-ID Number");
int customer_Id = input.nextInt();
input.nextLine();
for (int j = 0; j < i; j++) {
if (arr[j] != null)
arr[j].updateDetails(accnumber, acctype, minbal, ifsc, accholder, balance, customer_Id);
}
} else if (choice == 2) {
System.out.println("Enter Account To Get the details of any Account");
int accnumber = input.nextInt();
for (int j = 0; j < i; j++) {
arr[j].getDetails(accnumber);
}
} else if (choice == 3) {
System.out.println("Enter Account number and amount to deposit");
int accnumber = input.nextInt();
int amount = input.nextInt();
for (int j = 0; j < i; j++) {
arr[j].Deposit(accnumber, amount);
}
} else if (choice == 4) {
System.out.println("Enter Account number and amount to withdraw");
int accnumber = input.nextInt();
int amount = input.nextInt();
for (int j = 0; j < i; j++) {
arr[j].Withdraw(accnumber, amount);
}
} else if (choice == 5) {
System.out.println("Enter Account number to check Balance");
int accnumber = input.nextInt();
for (int j = 0; j < i; j++) {
float balance = arr[j].getBalance(accnumber);
if (balance != -1) {
System.out.println(
"------------------------------------------------------------------------------");
System.out.println("\tAvailable Balance : " + arr[j].getBalance(accnumber));
System.out.println(
"------------------------------------------------------------------------------");
}
}
} else if (choice == 6) {
System.out.println("------------------------------------------------------------------------------");
System.out.println("\tTotal number of accounts till now : " + arr[0].totalAccount());
System.out.println("------------------------------------------------------------------------------");
} else if (choice == 7) {
System.out.println("Enter Account Numbers to Compare");
int ac1 = input.nextInt();
int ac2 = input.nextInt();
Account acc1 = null, acc2 = null;
for (int j = 0; j < arr.length; j++) {
if (arr[j] == null) {
continue;
}
if (ac1 == arr[j].getAccNumber()) {
acc1 = arr[j];
}
}
for (int j = 0; j < arr.length; j++) {
if (arr[j] == null) {
continue;
}
if (ac2 == arr[j].getAccNumber()) {
acc2 = arr[j];
}
}
if (acc1 != null && acc2 != null) {
acc1.compare(acc1, acc2);
}
} else if (choice == 8) {
break;
} else {
System.out.println("Invalid Choice!");
}
}
input.close();
}
}