-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Program.cs
61 lines (52 loc) · 2.16 KB
/
Program.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
using System;
using System.Linq;
namespace customer_relationship
{
class Program
{
static void Main(string[] args)
{
// <SnippetTestDefaultImplementation>
SampleCustomer c = new SampleCustomer("customer one", new DateTime(2010, 5, 31))
{
Reminders =
{
{ new DateTime(2010, 08, 12), "childs's birthday" },
{ new DateTime(1012, 11, 15), "anniversary" }
}
};
SampleOrder o = new SampleOrder(new DateTime(2012, 6, 1), 5m);
c.AddOrder(o);
o = new SampleOrder(new DateTime(2103, 7, 4), 25m);
c.AddOrder(o);
// <SnippetHighlightCast>
// Check the discount:
ICustomer theCustomer = c;
Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}");
// </SnippetHighlightCast>
// </SnippetTestDefaultImplementation>
// Add more orders to get the discount:
DateTime recurring = new DateTime(2013, 3, 15);
for (int i = 0; i < 15; i++)
{
o = new SampleOrder(recurring, 19.23m * i);
c.AddOrder(o);
recurring.AddMonths(2);
}
Console.WriteLine($"Data about {c.Name}");
Console.WriteLine($"Joined on {c.DateJoined}. Made {c.PreviousOrders.Count()} orders, the last on {c.LastOrder}");
Console.WriteLine("Reminders:");
foreach (var item in c.Reminders)
{
Console.WriteLine($"\t{item.Value} on {item.Key}");
}
foreach (IOrder order in c.PreviousOrders)
Console.WriteLine($"Order on {order.Purchased} for {order.Cost}");
Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}");
// <SnippetSetLoyaltyThresholds>
ICustomer.SetLoyaltyThresholds(new TimeSpan(30, 0, 0, 0), 1, 0.25m);
Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}");
// </SnippetSetLoyaltyThresholds>
}
}
}