-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankProgram.cs
More file actions
126 lines (111 loc) · 4.06 KB
/
BankProgram.cs
File metadata and controls
126 lines (111 loc) · 4.06 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
using System.Text;
using static System.Console;
namespace Domain
{
public class BankProgram
{
private Dictionary<int, int> _accounts = new Dictionary<int, int>();
private double _rate = 0.01;
private int _newAccountNumber = 0;
private bool _isdone = default;
public static void Main()
{
BankProgram bankProgram = new ();
bankProgram.run();
}
public void run()
{
StringBuilder builder = new ();
builder.AppendLine("0 ---> Quit");
builder.AppendLine("1 ---> Create New Account");
builder.AppendLine("2 ---> Select Account");
builder.AppendLine("3 ---> Deposit Money");
builder.AppendLine("4 ---> Apply for loan");
builder.AppendLine("5 ---> Display Account Details");
builder.AppendLine("6 ---> Calculate Interest");
string menuMessage = builder.ToString();
WriteLine(menuMessage);
while(!_isdone)
{
Write("Hola! Welcome to BankYo App please enter your choice >> ");
int choice = int.Parse(ReadLine());
ProcessCommand(choice);
}
}
private void ProcessCommand(int choice)
{
if(choice == 0)
Quit();
else if(choice == 1)
CreateNewAccount();
else if(choice == 2)
SelectAccount();
else if(choice == 3)
DepositMoney();
else if(choice == 4)
ApplyForLoan();
else if(choice == 5)
DisplayAccountDetails();
else if(choice == 6)
CalculateInterest();
else
WriteLine("Invalid Choice");
}
private void Quit()
{
_isdone = true;
WriteLine("Thanks for using BankYo services see you soon");
}
private void CreateNewAccount()
{
_newAccountNumber++;
_accounts.Add(_newAccountNumber, 0);
WriteLine($"Your account number is {_newAccountNumber}");
}
private void SelectAccount()
{
Write("Insert account number >> ");
int accountNumber = int.Parse(ReadLine());
WriteLine($"Your BankYo accountnumber is :{accountNumber} and your balance is :{_accounts[accountNumber]}");
}
private void DepositMoney()
{
Write("Insert account number >> ");
int accountNumber = int.Parse(ReadLine());
Write("Insert amount >> ");
int amount = int.Parse(ReadLine());
int newBalance = _accounts[accountNumber] + amount;
_accounts[accountNumber] = newBalance;
WriteLine($"Your account balance is {newBalance}");
}
private void ApplyForLoan()
{
Write("Insert account number >> ");
int accountNumber = int.Parse(ReadLine());
Write("Insert loan amount >> ");
int loanAmount = int.Parse(ReadLine());
int balance = _accounts[accountNumber];
if(balance >= loanAmount/2)
WriteLine("Loan approved");
else
WriteLine("Loan Denied!!!");
}
public string DisplayAccountDetails()
{
StringBuilder builder = new StringBuilder();
var accountNumbers = _accounts.Keys;
foreach(int accountNumber in accountNumbers)
builder.AppendLine($"Your AccountNumber is : {accountNumber} and your balance is : {_accounts[accountNumber]}");
return builder.ToString();
}
public void CalculateInterest()
{
var accountNumbers = _accounts.Keys;
foreach(var accountNumber in accountNumbers)
{
int balance = _accounts[accountNumber];
_accounts[accountNumber] += (int) (balance * _rate);
}
}
}
}