-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingSystem.cs
More file actions
106 lines (94 loc) · 3.83 KB
/
Copy pathBankingSystem.cs
File metadata and controls
106 lines (94 loc) · 3.83 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
using System;
namespace BankingSystem
{
// Abstract class defining common structure for a bank account
abstract class BankAccount
{
public string AccountHolder { get; set; }
public decimal Balance { get; protected set; }
// Constructor for initializing account details
public BankAccount(string accountHolder, decimal initialBalance)
{
AccountHolder = accountHolder;
Balance = initialBalance;
}
// Abstract method for depositing money, must be implemented by derived classes
public abstract void Deposit(decimal amount);
// Abstract method for withdrawing money, must be implemented by derived classes
public abstract void Withdraw(decimal amount);
// Non-abstract method to display the balance, common to all types of accounts
public void DisplayBalance()
{
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.DisplayBalance)} {AccountHolder}'s Account Balance: {Balance:C}");
}
}
// SavingsAccount inherits from BankAccount and provides specific implementation for deposit and withdraw
class SavingsAccount : BankAccount
{
private const decimal WithdrawalLimit = 500; // Example limit for withdrawals
public SavingsAccount(string accountHolder, decimal initialBalance)
: base(accountHolder, initialBalance) { }
// Implementation of deposit
public override void Deposit(decimal amount)
{
if (amount > 0)
{
Balance += amount;
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.DepositSuccess)} {amount:C} to {AccountHolder}'s savings account.");
}
else
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InvalidInput));
}
}
// Implementation of withdraw with a limit check
public override void Withdraw(decimal amount)
{
if (amount > Balance)
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InsufficientFunds));
}
else if (amount > WithdrawalLimit)
{
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.WithdrawalLimitExceeded)} {WithdrawalLimit:C} at once.");
}
else
{
Balance -= amount;
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.WithdrawSuccess)} {amount:C} from {AccountHolder}'s savings account.");
}
}
}
// CurrentAccount inherits from BankAccount and has no withdrawal limit
class CurrentAccount : BankAccount
{
public CurrentAccount(string accountHolder, decimal initialBalance)
: base(accountHolder, initialBalance) { }
// Implementation of deposit
public override void Deposit(decimal amount)
{
if (amount > 0)
{
Balance += amount;
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.DepositSuccess)} {amount:C} to {AccountHolder}'s current account.");
}
else
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InvalidInput));
}
}
// Implementation of withdraw without a limit
public override void Withdraw(decimal amount)
{
if (amount > Balance)
{
Console.WriteLine(Messages.GetMessage(Messages.MessageType.InsufficientFunds));
}
else
{
Balance -= amount;
Console.WriteLine($"{Messages.GetMessage(Messages.MessageType.WithdrawSuccess)} {amount:C} from {AccountHolder}'s current account.");
}
}
}
}