summaryrefslogtreecommitdiff
path: root/lib/account.cs
blob: 8aadc581ee99064410da2749b37e684d9e364f0d (plain)
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
using System.Collections.Generic;

public class Account
{
  IList<Entry> entries;

  public Account()
  {
    this.entries = new List<Entry>();
  }

  public void deposit(Quantity quantity)
  {
    this.entries.Add(new Deposit(quantity));
  }

  public void withdraw(Quantity quantity)
  {
    this.entries.Add(new Withdrawal(quantity));
  }

  public void transfer(Quantity quantity, Account to)
  {
    withdraw(quantity);
    to.deposit(quantity);
  }

  public Quantity balance()
  {
    Quantity total = new Quantity(0, Currency.CAD);
    foreach (var entry in this.entries)
    {
      total = entry.apply_to(total);
    }
    return total;
  }
}