forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.cs
More file actions
73 lines (63 loc) · 1.67 KB
/
Account.cs
File metadata and controls
73 lines (63 loc) · 1.67 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
using System;
using System.Collections.Generic;
using System.Numerics;
namespace DigitalWallet
{
public class Account
{
private readonly string id;
private readonly User user;
private readonly string accountNumber;
private readonly Currency currency;
private decimal balance;
private readonly List<Transaction> transactions;
public Account(string id, User user, string accountNumber, Currency currency)
{
this.id = id;
this.user = user;
this.accountNumber = accountNumber;
this.currency = currency;
this.balance = 0.0M;
this.transactions = new List<Transaction>();
}
public void Deposit(decimal amount)
{
balance = balance + amount;
}
public void Withdraw(decimal amount)
{
if (balance.CompareTo(amount) >= 0)
{
balance = balance - amount;
}
else
{
throw new InsufficientFundsException("Insufficient funds in the account.");
}
}
public void AddTransaction(Transaction transaction)
{
transactions.Add(transaction);
}
public string GetId()
{
return id;
}
public User GetUser()
{
return user;
}
public Currency GetCurrency()
{
return currency;
}
public decimal GetBalance()
{
return balance;
}
public List<Transaction> GetTransactions()
{
return transactions;
}
}
}