-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueList
59 lines (47 loc) · 1.71 KB
/
QueueList
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
import java.util.LinkedList;
import java.util.Queue;
public class QueueSystem {
private Queue<String> queue;
private boolean isSupervisorOnline;
private String supervisorUsername;
public QueueSystem() {
this.queue = new LinkedList<>();
this.isSupervisorOnline = false;
this.supervisorUsername = "";
}
public void joinQueue(String userName) {
queue.add(userName);
System.out.println(userName + " joined the queue.");
}
public int getPosition(String userName) {
int position = 0;
for (String user : queue) {
if (user.equals(userName)) {
return position;
}
position++;
}
return -1;
}
public void setSupervisorStatus(boolean online, String username) {
isSupervisorOnline = online;
supervisorUsername = online ? username : "";
System.out.println("Supervisor " + (online ? username + " is now online" : "is now offline"));
}
public boolean isSupervisorOnline() {
return isSupervisorOnline;
}
public String getSupervisorUsername() {
return supervisorUsername;
}
public static void main(String[] args) {
QueueSystem queueSystem = new QueueSystem();
queueSystem.setSupervisorStatus(true, "Supervisor1");
queueSystem.joinQueue("User1");
queueSystem.joinQueue("User2");
queueSystem.joinQueue("User3");
System.out.println("User2 is at position: " + queueSystem.getPosition("User2"));
System.out.println("Is Supervisor online? " + queueSystem.isSupervisorOnline());
System.out.println("Supervisor username: " + queueSystem.getSupervisorUsername());
}
}