-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orders.cs
132 lines (102 loc) · 3.15 KB
/
Orders.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace PizzaOrderingSystem
{
class Orders
{
private ArrayList itemList;
private Customer cust;
public Customer Cust
{
get
{
return cust;
}
}
public Orders(Customer cust)
{
this.cust = cust;
itemList = new ArrayList();
}
public void RecordAnItem(OrderItem item)
{
itemList.Add(item);
}
public OrderItem[] GetItemList()
{
OrderItem[] item = new OrderItem[itemList.Count];
for (int i = 0; i < itemList.Count; i++)
item[i] = (OrderItem)itemList[i];
return item;
}
public double ComputeDeliveryCharge(double price)
{
if (price < 20)
return 5;
else
return 0;
}
public double ComputeTotalPrice()
{
double totalPrice = 0;
foreach (OrderItem i in GetItemList())
totalPrice += (i.ComputePricePerUnit() * i.Quantity);
totalPrice += ComputeDeliveryCharge(totalPrice);
return totalPrice;
}
public void UpdateItemQuantity(int index, OrderItem item)
{
itemList.RemoveAt(index);
RecordAnItem(item);
}
public int CheckDuplicatePizza(Pizza p)
{
int index = -1;
bool toppingCompare = true;
OrderItem[] item = GetItemList();
for (int i = 0; i < item.Length; i++)
{
if (item[i] is Pizza)
{
Pizza piz = (Pizza)item[i];
string[] topping = piz.GetToppingList();
string[] pTopping = p.GetToppingList();
foreach(string old in topping)
foreach (string compare in pTopping)
{
if (old == null || compare == null || old != compare)
toppingCompare = false;
else
toppingCompare = true;
}
if (piz.Type == p.Type && piz.Size == p.Size && topping.Length == pTopping.Length && toppingCompare)
{
index = i;
break;
}
}
}
return index;
}
public int CheckDuplicateDrink(Drink d)
{
int index = -1;
OrderItem[] item = GetItemList();
for (int i = 0; i < item.Length; i++)
{
if (item[i] is Drink)
{
Drink drk = (Drink)item[i];
if (drk.Size == d.Size && drk.Type == d.Type )
{
index = i;
break;
}
}
}
return index;
}
}
}