-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pizza.cs
120 lines (97 loc) · 3.39 KB
/
Pizza.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;
using System.Linq;
namespace PizzaOrderingSystem
{
public class Pizza:OrderItem
{
private ArrayList toppingList;
private static readonly string[] toppingChoice = { "Cheese", "Mushrooms", "Sausage", "Pepperoni", "Cherry Tomato", "Onions" };
public string[] ToppingChoice
{
get
{
return toppingChoice;
}
}
private static readonly string[] pizzaTypeChoice = { "Thin", "Thick" };
private static readonly double[] pizzaSizePrice = { 9.00, 16.00, 22.00 };
private static readonly double[] pizzaToppingPrice = { 2.50, 2.00, 3.50, 4.50, 1.50, 1.20 };
public string[] PizzaTypeChoice
{
get
{
return pizzaTypeChoice;
}
}
public Pizza()
: base()
{
toppingList = new ArrayList();
}
public Pizza(string size, string type, string[] topping, int quantity)
: base(size, type, quantity)
{
toppingList = new ArrayList(topping);
}
public void RecordTopping(int topping)
{
if (topping < 1 || topping > 6)
throw new ArgumentOutOfRangeException("", "Value should be ranged from '1' to '6' only!");
else
for (int i = 0; i < toppingChoice.Length; i++)
if (topping == i + 1)
toppingList.Add(toppingChoice[i]);
}
public string[] GetToppingList()
{
string[] topping = new string[toppingList.Count];
for (int i = 0; i < toppingList.Count; i++)
topping[i] = (string)toppingList[i];
Array.Sort(topping);
return topping;
}
public override string ObtainSize(int choice)
{
switch (choice)
{
case 1:
return SizeChoice[0]; //Small
case 2:
return SizeChoice[1]; //Medium
case 3:
return SizeChoice[2]; //Large
default:
throw new ArgumentOutOfRangeException("", "Value should be ranged from '1' to '3' only!");
}
}
public override string ObtainType(int choice)
{
switch (choice)
{
case 1:
return pizzaTypeChoice[0]; //Thin
case 2:
return pizzaTypeChoice[1]; //Thick
default:
throw new ArgumentOutOfRangeException("", "Value should be ranged from '1' to '2' only!");
}
}
public override double ComputePricePerUnit()
{
double toppingPrice = 0, sizePrice = 0;
for(int i=0;i<SizeChoice.Length;i++)
if (Size == SizeChoice[i])
sizePrice = pizzaSizePrice[i];
string[] topping = GetToppingList();
for (int i = 0; i < topping.Length; i++)
for (int j = 0; j < toppingChoice.Length; j++)
if (topping[i] == toppingChoice[j])
toppingPrice += pizzaToppingPrice[j];
return sizePrice + toppingPrice;
}
}
}