-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestaurant.java
93 lines (74 loc) · 1.6 KB
/
Restaurant.java
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
import java.util.HashMap;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
public class Restaurant {
private Table[] tables;
private HashMap<String, Double> menu;
private Queue<Group> line;
private double revenue = 0;
public Restaurant(Table[] t, HashMap<String, Double> m)
{
tables = t;
menu = m;
line = new LinkedBlockingQueue<Group>();
}
public void addGroup(Group g1)
{
line.add(g1);
checkTables();
}
public boolean checkTables()
{
for(Group g : line)
{
Table t = getTable(g.getNumOfPeople());
if( t != null)
{
System.out.println(g.getName() + ", your table is ready.");
line.remove(g);
t.filledUp(g);
return true;
}
else
System.out.println("Sorry, " + g.getName() + " , there are unfortunately no tables avaiable for your right now.");
}
return false;
}
private Table getTable(int numOfCustomers)
{
for(int x = 0; x < tables.length; x++)
{
if(numOfCustomers == tables[x].getCapacity() && tables[x].getAvailability())
{
return tables[x];
}
}
return null;
}
public void emptyTable(Group g1)
{
revenue += g1.getFullPrice();
for(int x = 0; x < tables.length; x++)
{
if(tables[x].getGroup() != null && tables[x].getGroup().equals(g1))
{
System.out.println("Bye, " + tables[x].getGroup().getName() + " please come again!");
tables[x].emptyTable();
}
}
checkTables();
}
public double getRevenue()
{
return revenue;
}
public boolean allFilledUp()
{
for(Table t : tables)
{
if(t.getAvailability())
return false;
}
return true;
}
}