Repository navigation
Expand file tree
/
Copy pathprogram.cs
More file actions
216 lines (132 loc) · 4.73 KB
/
Copy pathprogram.cs
File metadata and controls
216 lines (132 loc) · 4.73 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
// See https://aka.ms/new-console-template for more information
using TestAccount;
Bank SuperBanking = new Bank();
//Console.WriteLine(EnumClass.ReadUserOptions());
int x = -1;
do
{
switch (EnumClass.ReadUserOptions())
{
case EnumClass.MenuOption.Withdraw: DoWithdraw(SuperBanking); break;
case EnumClass.MenuOption.Deposit: DoDeposit(SuperBanking); break;
case EnumClass.MenuOption.Print: Print(SuperBanking); break;
case EnumClass.MenuOption.Transfer: Transfer(SuperBanking); break;
case EnumClass.MenuOption.AddAccount: AddAccount(SuperBanking); break;
case EnumClass.MenuOption.Quit: Console.WriteLine("Thank you for using SuperBanking, Come back!"); x = -2; break;
default: Console.WriteLine("unexpected error occured"); break;
}
} while (x == -1);
static Account FindAccount(Bank bank)
{
Console.WriteLine("Enter the name of the account");
String _name = Console.ReadLine();
if (bank.GetAccount(_name) != null)
{
Console.WriteLine($"Account {bank.GetAccount(_name).Name} found!");
return bank.GetAccount(_name);
}
// No need to say no here since bank account will already throw an exception if it is not found
return null;
}
static void DoDeposit(Bank SuperBanking)
{
Console.WriteLine();
Console.WriteLine("DEPOSIT");
Account _accountName = FindAccount(SuperBanking);
if (_accountName != null)
{
_accountName.print();
Console.WriteLine();
Console.WriteLine("Enter the amount you want to Deposit");
decimal temp = Convert.ToDecimal(Console.ReadLine());
DepositTransaction depositObj = new DepositTransaction(_accountName, temp);
SuperBanking.ExecuteTransaction(depositObj);
}
}
static void Transfer(Bank SuperBanking)
{
Console.WriteLine();
Console.WriteLine("TRANSFER");
Console.WriteLine();
Console.WriteLine("Account 1 to Account 2");
Console.WriteLine("Enter Account 1");
Account _accountName = FindAccount(SuperBanking);
if (_accountName != null)
{
Console.WriteLine($"Account 1: {_accountName.Name} - ${_accountName.Balance}");
Console.WriteLine("Enter Account 2");
Account _accountName2 = FindAccount(SuperBanking);
if (_accountName2 != null)
{
Console.WriteLine($"Account 2: {_accountName2.Name} - ${_accountName2.Balance}");
Console.WriteLine($"Transfering from {_accountName.Name} to >> {_accountName2.Name}");
Console.WriteLine("Enter the amount you want to Transfer");
decimal temp = Convert.ToDecimal(Console.ReadLine());
TranserTransaction transferObj = new TranserTransaction(_accountName, _accountName2, temp);
SuperBanking.ExecuteTransaction(transferObj);
_accountName.print();
_accountName2.print();
}
}
}
static void DoWithdraw(Bank SuperBanking)
{
Account _accountName = FindAccount(SuperBanking);
if (_accountName != null)
{
_accountName.print();
Console.WriteLine();
Console.WriteLine("Enter the amount you want to Withdraw");
decimal temp = Convert.ToDecimal(Console.ReadLine());
DepositTransaction depositObj = new DepositTransaction(_accountName, temp);
SuperBanking.ExecuteTransaction(depositObj);
}
// account.deposit(temp);
}
static void Print(Bank bank)
{
Account printing = FindAccount(bank);
printing.print();
}
void AddAccount(Bank bank)
{
Console.WriteLine("name of your new account");
String _name = Console.ReadLine();
Console.WriteLine("balance of your new account");
decimal _amount = Convert.ToDecimal(Console.ReadLine());
bank.AddAccount(new Account(_name, _amount));
}
public static class EnumClass
{
public enum MenuOption
{
Withdraw,
Deposit,
Print,
Transfer,
AddAccount,
Quit
}
public static MenuOption ReadUserOptions()
{
int num = 1;
int selectio;
foreach (var item in Enum.GetNames(typeof(MenuOption)))
{
Console.WriteLine($"{item} --> {num}");
num++;
}
do
{
Console.WriteLine();
Console.WriteLine("Enter your selection from the above");
int selection = Convert.ToInt32(Console.ReadLine());
if ((selection > 0 ) && (selection <= Enum.GetNames(typeof(MenuOption)).Length))
{
selectio = selection;
break;
}
} while (true);
return (MenuOption)selectio -1;
}
}