-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank.cs
111 lines (105 loc) · 3.2 KB
/
Bank.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
using System;
using System.Collections.Generic;
using System.Text;
namespace MidAssignment1
{
class Bank
{
private string bankName;
private Account[] myBank;
public Bank(string bankName, int size)
{
this.bankName = bankName;
this.myBank = new Account[size];
}
public string BankName
{
set { this.bankName = value; }
get { return this.bankName; }
}
public Account[] MyBank
{
get { return this.myBank; }
}
public void AddAccount(Account account)
{
bool flag = false;
for (int i = 0; i < myBank.Length; i++)
{
if (myBank[i] == null)
{
myBank[i] = account;
flag = true;
myBank[i].AccountNumber = i;
break;
}
}
if (flag) Console.WriteLine("Account Added.....");
else Console.WriteLine("Can not add.....");
}
public void DeleteAccount(int accountNumber)
{
bool flag = false;
for (int i = 0; i < myBank.Length; i++)
{
if (myBank[i] == null) continue;
else if (accountNumber == myBank[i].AccountNumber)
{
myBank[i] = null;
for (int j = i; j < myBank.Length - 1; j++)
{
Account x = myBank[j];
myBank[j] = myBank[j + 1];
myBank[j + 1] = x;
}
flag = true;
}
}
if (flag) Console.WriteLine("Account Deleted....");
else Console.WriteLine("Can not delete.....");
}
public void Transaction(int transactionType, params dynamic[] x)
{
if (transactionType == 1)
{
myBank[x[0]].Widraw(x[1]);
}
else if (transactionType == 2)
{
myBank[x[0]].Diposit(x[1]);
}
else if (transactionType == 3)
{
myBank[x[0]].Transfer(myBank[x[1]], x[2]);
}
else
{
Console.WriteLine("You gave a wrong input....");
}
}
public int SearchAccount(int accountNumber)
{
bool flag = false;
int i = 0;
for (i = 0; i < myBank.Length; i++)
{
if (myBank[i] == null) continue;
else if (myBank[i].AccountNumber == accountNumber)
{
flag = true;
break;
}
}
if (flag) return i;
else return -1;
}
public void PrintAccountDetails()
{
Console.WriteLine("Bank Name : " + this.bankName);
for(int i = 0; i < myBank.Length; i++)
{
myBank[i].ShowAccountInfo();
}
}
}
}