-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDev.cs
94 lines (76 loc) · 2.23 KB
/
Dev.cs
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
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Vend2000
{
public class CoinValidator : ICoinValidator
{
//public IResult<bool> Validate(ICoin coin, CoinType coinType)
//{
// if (coin.CoinType != coinType)
// {
// return Result.Fail(false, $"Invalid coin: {coin.Name}");
// }
// return Result.Success(true);
//}
public CoinType DetermineCoinType(ICoin coin)
{
if (coin.Diameter == 30 && coin.Weight == 11)
{
return CoinType.Gold;
}
if (coin.Diameter == 24 && coin.Weight == 5)
{
return CoinType.Silver;
}
if (coin.Diameter == 17 && coin.Weight == 2)
{
return CoinType.Bronze;
}
return CoinType.Unknown;
}
}
public class GumDispenser10Unit : IGumDispenser
{
private readonly Queue<GumPacket> queue = new Queue<GumPacket>(10);
public GumDispenser10Unit()
{
queue.Enqueue(new GumPacket());
queue.Enqueue(new GumPacket());
queue.Enqueue(new GumPacket());
}
public int Capacity => 10;
public int Quantity => queue.Count;
public void Add(GumPacket gumPacket)
{
if (Quantity >= Capacity)
{
return;
}
queue.Enqueue(gumPacket);
}
GumPacket IGumDispenser.Dispense()
{
if (Quantity <= 0)
{
return null;
}
return queue.Dequeue();
}
}
public class CoinStorage : ICoinStorage
{
public int CoinCount => coins.Count;
private readonly List<ICoin> coins = new List<ICoin>();
public List<ICoin> Empty()
{
var coinsCopy = coins.Select(coin => coin).ToList();
coins.Clear();
return coinsCopy;
}
public void Add(ICoin coin)
{
coins.Add(coin);
}
}
}