-
Notifications
You must be signed in to change notification settings - Fork 0
/
eBanke.cs
378 lines (351 loc) · 14.8 KB
/
eBanke.cs
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
// Developer: Nnachi, Joseph Otu
// Project: eBanke: Core Banking Software Application
// (Copyright (c)2024)
using System;
using System.Collections.Generic;
namespace CoreBankingSoftware
{
public enum AccountType
{
QSavings, //Q-Savings Account = 10,000,000.
Savings, //Savings Account = unlimited Amount
FixedDeposit, //Capacity = Unlimited
CurrentIndividual, //Capacity = Unlimited
CurrentCorporate, //Capacity = Unlimited
CurrentNonProfit //Capacity = Unlimited
}
public enum AccountStatus
{
New,
Active,
Inactive,
UnderAudit,
Frozen,
Closed
}
public class Account
{
public string Name { get; private set; }
public string Address { get; private set; }
public string AccountNumber { get; private set; }
public string AccountHolderName { get; set; }
public decimal Balance { get; private set; }
public AccountType Type { get; private set; }
public AccountStatus Status { get; set; }
public DateTime CreationDate { get; private set; }
public DateTime DateOfBirth { get; set; }
public Account(string name, string address, AccountType type, DateTime dateOfBirth)
{
Name = name;
Address = address;
AccountNumber = GenerateAccountNumber();
Balance = 0;
Status = AccountStatus.Active;
Type = type;
CreationDate = DateTime.Now; // Set the creation date to current date and time
DateOfBirth = dateOfBirth;
}
private string GenerateAccountNumber()
{
Random rand = new Random();
int randomNumber = rand.Next(10000000, 99999999); // Generate an 8-digit random number
return $"ACCT{randomNumber}"; // Prefixing with "ACCT" for better readability
}
public void Deposit(decimal amount)
{
Balance += amount;
}
public bool Withdraw(decimal amount)
{
if (amount <= Balance)
{
Balance -= amount;
return true;
}
else
{
Console.WriteLine("Insufficient funds.");
return false;
}
}
}
public class CoreBankingSystem
{
private static List<Account> accounts = new List<Account>();
private static int customerCount = 0;
private const int MaxCustomers = 1000; // Assuming a maximum of 1000 customers
public static void CreateAccount()
{
if (customerCount >= MaxCustomers)
{
Console.WriteLine("Sorry, maximum number of accounts has been reached. ");
return;
}
Console.WriteLine("\nCreate Account:");
Console.Write(" Enter your name: ");
string name = Console.ReadLine();
Console.Write(" Enter your address: ");
string address = Console.ReadLine();
Console.Write(" Enter your date of birth and tap [ENTER] twice (YYYY-MM-DD): ");
DateTime dateOfBirth = DateTime.Parse(Console.ReadLine());
Console.WriteLine(" Select Account Type: ");
Console.WriteLine(" 1. Q-Savings Accounts ");
Console.WriteLine(" 2. Savings Account ");
Console.WriteLine(" 3. Fixed Deposit Account ");
Console.WriteLine(" 4. Current Account [Corporate] ");
Console.WriteLine(" 5. Current Account [Individual] ");
Console.WriteLine(" 6. Current Account [Non-Profit] \n");
Console.Write($" Kindly enter any number from [1-6] to select type of account: ");
string accType = Console.ReadLine();
AccountType type;
switch (accType)
{
case "1":
type = AccountType.QSavings;
break;
case "2":
type = AccountType.Savings;
break;
case "3":
type = AccountType.FixedDeposit;
break;
case "4":
type = AccountType.CurrentCorporate;
break;
case "5":
type = AccountType.CurrentIndividual;
break;
case "6":
type = AccountType.CurrentNonProfit;
break;
default:
Console.WriteLine("Invalid account type. Account creation failed. ");
return;
}
// Generate a unique account number (you should implement this)
int accountNumber = GenerateAccountNumber();
// Create the account
Account account = new Account(name, address, type, dateOfBirth);
accounts.Add(account);
customerCount++;
Console.WriteLine();
Console.WriteLine($" Account created successfully! [Account Number: {account.AccountNumber} ], Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}, Creation Date: {account.CreationDate}");
}
private static int GenerateAccountNumber()
{
// This method should generate a unique account number
// You can implement your logic here
// For simplicity, let's just return a random number for now
Random rand = new Random();
return rand.Next(10000000, 99999999); // Return a 8-digit random number
}
public static void ViewAllAccounts()
{
Console.WriteLine("\nAll Accounts:");
foreach (var account in accounts)
{
Console.WriteLine($" [Account Number: {account.AccountNumber} ], Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}, Creation Date: {account.CreationDate} ");
}
}
public static void ViewAccountByAccountNumber()
{
Console.Write("Enter Account Number: ");
string accNumber = Console.ReadLine();
var account = accounts.Find(acc => acc.AccountNumber == accNumber);
if (account != null)
{
Console.WriteLine($" [Account Number: {account.AccountNumber} ], Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}, Creation Date: {account.CreationDate}");
}
else
{
Console.WriteLine("Account not found.");
}
}
// Frozen Accounts
public static void ViewFrozenAccounts()
{
Console.WriteLine("\nFrozen Accounts:");
foreach (var account in accounts)
{
if (account.Status == AccountStatus.Frozen)
{
Console.WriteLine($"Account Number: {account.AccountNumber}, Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}");
}
}
}
public static void ViewAccountsWithBalance()
{
Console.WriteLine("\nAccounts with Balance:");
foreach (var account in accounts)
{
if (account.Balance > 0)
{
Console.WriteLine($"Account Number: {account.AccountNumber}, Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}");
}
}
}
public static void ViewEligibleAccountsForLoan()
{
// Implement logic to determine eligibility for a loan
Console.WriteLine("\nEligible Accounts for Loan:");
foreach (var account in accounts)
{
// Sample logic: Check balance, type, etc.
if (account.Balance >= 1000 && account.Type == AccountType.Savings)
{
Console.WriteLine($"Account Number: {account.AccountNumber}, Name: {account.Name}, Type: {account.Type}, Balance: {account.Balance}");
}
else
{
Console.WriteLine(" No Account Found, [FUND] Account");
}
}
}
// FundsDeposit Class
public static void DepositFunds()
{
Console.Write("Enter Account Number: ");
string accNumber = Console.ReadLine();
var account = accounts.Find(acc => acc.AccountNumber == accNumber);
if (account != null)
{
Console.Write("Enter amount to deposit: ");
decimal amount = Convert.ToDecimal(Console.ReadLine());
account.Deposit(amount);
Console.WriteLine($"Deposit successful. Updated Balance: {account.Balance}");
}
else
{
Console.WriteLine("Account not found.");
}
}
// FundsWithdraw Class
public static void WithdrawFunds()
{
Console.Write("Enter Account Number: ");
string accNumber = Console.ReadLine();
var account = accounts.Find(acc => acc.AccountNumber == accNumber);
if (account != null)
{
Console.Write("Enter amount to withdraw: ");
decimal amount = Convert.ToDecimal(Console.ReadLine());
if (account.Withdraw(amount))
{
Console.WriteLine($"Withdrawal successful. Updated Balance: {account.Balance}");
}
}
else
{
Console.WriteLine("Account not found.");
}
}
public static void TransferFunds()
{
Console.Write("Enter Sender's Account Number: ");
string sourceAccNumber = Console.ReadLine();
var sourceAccount = accounts.Find(acc => acc.AccountNumber == sourceAccNumber);
if (sourceAccount != null)
{
Console.Write("Enter Recipient's Account Number: ");
string destAccNumber = Console.ReadLine();
var destAccount = accounts.Find(acc => acc.AccountNumber == destAccNumber);
if (destAccount != null)
{
Console.Write("Enter amount to transfer: ");
decimal amount = Convert.ToDecimal(Console.ReadLine());
if (sourceAccount.Withdraw(amount))
{
destAccount.Deposit(amount);
Console.WriteLine($"Transfer successful. Updated Balance of Source Account: {sourceAccount.Balance}, Updated Balance of Destination Account: {destAccount.Balance}");
}
else
{
Console.WriteLine(" Transfer failed due to insufficient funds. ");
}
}
else
{
Console.WriteLine("Recipient's Account not found.");
}
}
else
{
Console.WriteLine("Source Account not found.");
}
}
}
class Program
{
static void Main(string[] args)
{
bool done = false;
while (!done)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" Welcome to eBanke!");
Console.WriteLine(" Respond to the prompt then, press [ENTER] to continue ");
Console.WriteLine();
Console.WriteLine();
Console.Write(" Please enter your name? ");
string nom = Console.ReadLine();
while (!done)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine($" Hello {nom}! What would you want to do with eBanke today?");
Console.WriteLine();
Console.WriteLine(" 1. Create Account");
Console.WriteLine(" 2. View All Accounts");
Console.WriteLine(" 3. View Account by Account Number");
Console.WriteLine(" 4. View Frozen Accounts");
Console.WriteLine(" 5. View Accounts with Balance");
Console.WriteLine(" 6. View Eligible Accounts for Loan");
Console.WriteLine(" 7. Deposit Funds");
Console.WriteLine(" 8. Withdraw Funds");
Console.WriteLine(" 9. Transfer Funds");
Console.WriteLine(" 0. Exit \n");
Console.Write($" {nom}, Kindly enter any number from [1-5] to try eBanke [0] to EXIT ebanke: ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
CoreBankingSystem.CreateAccount();
break;
case "2":
CoreBankingSystem.ViewAllAccounts();
break;
case "3":
CoreBankingSystem.ViewAccountByAccountNumber();
break;
case "4":
CoreBankingSystem.ViewFrozenAccounts();
break;
case "5":
CoreBankingSystem.ViewAccountsWithBalance();
break;
case "6":
CoreBankingSystem.ViewEligibleAccountsForLoan();
break;
case "7":
CoreBankingSystem.DepositFunds();
break;
case "8":
CoreBankingSystem.WithdrawFunds();
break;
case "9":
CoreBankingSystem.TransferFunds();
break;
case "0":
Console.WriteLine("Exiting eBanke..");
done = true;
break;
default:
Console.WriteLine("Invalid option! Please try again.");
break;
}
}
}
}
}
}