-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarket.java
More file actions
52 lines (43 loc) · 1.63 KB
/
Copy pathMarket.java
File metadata and controls
52 lines (43 loc) · 1.63 KB
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
import java.util.ArrayList;
import java.util.List;
class Market implements QueueBehaviour, MarketBehaviour, UpdateMarket {
private List<Client> queue; // Список людей в очереди
private List<Client> servedClients; // Список обслуженных покупателей
public Market() {
this.queue = new ArrayList<>();
this.servedClients = new ArrayList<>();
}
// Методы из интерфейса QueueBehaviour
@Override
public void addToQueue(Client client) {
queue.add(client);
}
@Override
public Client removeFromQueue() {
if (!queue.isEmpty()) {
Client client = queue.get(0);
queue.remove(0);
return client;
}
return null;
}
// Методы из интерфейса MarketBehaviour
@Override
public void clientArrived(Client client) {
addToQueue(client);
} //Переопределение добавление в очередь
@Override
public void clientLeft(Client client) {
queue.remove(client);
}//Переопределение удаление из очереди
@Override
public void update() {
if (!queue.isEmpty()) {
Client client = removeFromQueue();//Удаление клиента из очереди
servedClients.add(client);//Добавить в обслуженных клиентов
System.out.println("Заказ принят и выдан:" + client.getName());
} else {
System.out.println("Нет клиентов в очереди");
}
}
}