-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFood.cs
76 lines (57 loc) · 1.23 KB
/
Food.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
public class Meal
{
public string Name { get; set; }
public decimal Price { get; set; }
public Meal()
{
}
public Meal(string name, decimal price)
{
Name = name;
Price = price;
}
}
public class MealPurchase
{
public Meal Meal { get; set; }
public int Quantity { get; set; }
public Payment Payment { get; private set; }
public MealPurchase(Meal meal, int quantity)
{
Meal = meal;
Quantity = quantity;
}
public decimal GetTotalPrice()
{
return Meal.Price * Quantity;
}
public void RecordPayment(decimal amount)
{
if (Payment == null) // Ensures that a payment can only be recorded once
{
Payment = new Payment(amount);
}
else
{
Console.WriteLine("Payment has already been recorded for this purchase.");
}
}
}
public class MealTracker
{
private List<MealPurchase> purchases;
public MealTracker()
{ }
public void AddPurchase(MealPurchase purchase)
{
purchases.Add(purchase);
}
}
public class Payment
{
public decimal Amount { get; set; }
public Payment(decimal amount)
{
Amount = amount;
}
}