-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticketQueue.java
More file actions
42 lines (39 loc) · 1.41 KB
/
ticketQueue.java
File metadata and controls
42 lines (39 loc) · 1.41 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
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class ticketQueue {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Queue<String> queue = new LinkedList<>();
while (true) {
System.out.println("\n1. Book Ticket");
System.out.println("2. Serve Ticket");
System.out.println("3. Show Queue");
System.out.println("4. Exit");
System.out.print("Choice: ");
int ch = sc.nextInt();
sc.nextLine();
if (ch == 1) {
System.out.print("Enter name: ");
String name = sc.nextLine();
queue.add(name);
System.out.println("Ticket booked for " + name);
} else if (ch == 2) {
if (!queue.isEmpty()) {
System.out.println("Now serving: " + queue.poll());
} else {
System.out.println("Queue is empty.");
}
} else if (ch == 3) {
System.out.println("Current Queue:");
for (String name : queue) {
System.out.println("- " + name);
}
} else if (ch == 4) {
break;
} else {
System.out.println("Invalid.");
}
}
}
}