-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (87 loc) · 3.62 KB
/
Copy pathProgram.cs
File metadata and controls
101 lines (87 loc) · 3.62 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
using BankingSystem;
using System;
namespace ConsoleApp
{
// Program to run the banking system
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.Welcome));
// Creating instances of accounts
BankAccount savings = new SavingsAccount("Alice", 1000);
BankAccount current = new CurrentAccount("Bob", 5000);
while (true)
{
DisplayMenu();
Console.WriteLine(Messages.GetMessage(Messages.MessageType.MenuPrompt));
string choice = Console.ReadLine();
switch (choice)
{
case "1":
Console.WriteLine(Messages.GetMessage(Messages.MessageType.DepositPrompt));
decimal savingsDeposit = GetValidAmount();
savings.Deposit(savingsDeposit);
break;
case "2":
Console.WriteLine(Messages.GetMessage(Messages.MessageType.WithdrawPrompt));
decimal savingsWithdraw = GetValidAmount();
savings.Withdraw(savingsWithdraw);
break;
case "3":
Console.WriteLine(Messages.GetMessage(Messages.MessageType.DepositPrompt));
decimal currentDeposit = GetValidAmount();
current.Deposit(currentDeposit);
break;
case "4":
Console.WriteLine(Messages.GetMessage(Messages.MessageType.WithdrawPrompt));
decimal currentWithdraw = GetValidAmount();
current.Withdraw(currentWithdraw);
break;
case "5":
savings.DisplayBalance();
break;
case "6":
current.DisplayBalance();
break;
case "7":
Console.WriteLine(Messages.GetMessage(Messages.MessageType.ExitMessage));
return;
default:
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InvalidOption));
break;
}
}
}
// Method to display the menu options
static void DisplayMenu()
{
Console.WriteLine("\n--- Banking System Menu ---");
Console.WriteLine("1. Deposit to Savings Account");
Console.WriteLine("2. Withdraw from Savings Account");
Console.WriteLine("3. Deposit to Current Account");
Console.WriteLine("4. Withdraw from Current Account");
Console.WriteLine("5. Display Savings Account Balance");
Console.WriteLine("6. Display Current Account Balance");
Console.WriteLine("7. Exit");
}
// Method to validate and convert user input to a decimal amount
static decimal GetValidAmount()
{
decimal amount;
while (true)
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.EnterAmount));
string input = Console.ReadLine();
if (decimal.TryParse(input, out amount) && amount > 0)
{
return amount;
}
else
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InvalidInput));
}
}
}
}
}