-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoney.cs
More file actions
63 lines (49 loc) · 1.36 KB
/
Money.cs
File metadata and controls
63 lines (49 loc) · 1.36 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
using System;
namespace TDD_Money
{
public class Money : Expression
{
internal readonly int Amount;
private readonly string _currency;
public Money(int amount, string currency)
{
this.Amount = amount;
this._currency = currency;
}
public static Money Dollar(int amount)
{
return new Money(amount, "USD");
}
public static Money Franc(int amount)
{
return new Money(amount, "CHF");
}
public override bool Equals(Object obj)
{
Money money = (Money) obj;
return money.Amount == this.Amount
&& _currency.Equals(money._currency);
}
public Expression Times(int multiplier)
{
return new Money(Amount * multiplier, _currency);
}
public Expression Plus(Expression addend)
{
return new Sum(this, addend);
}
public string Currency()
{
return this._currency;
}
public override string ToString()
{
return Amount + " " + _currency;
}
public Money Reduce(Bank bank, string toCurrency)
{
var rate = bank.Rate(_currency, toCurrency);
return new Money(Amount/rate,toCurrency);
}
}
}