-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupprtTicketSystem.java
More file actions
82 lines (73 loc) · 2.54 KB
/
SupprtTicketSystem.java
File metadata and controls
82 lines (73 loc) · 2.54 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
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
import java.util.Scanner;
class SupprtTicketSystem {
private static int front, rear, size, capacity;
private static String[] ticketQueue;
SupprtTicketSystem(int size) {
front = rear = 0;
capacity = size;
ticketQueue = new String[capacity];
}
static void enqueue(String ticket) {
if (size == capacity) {
System.out.println("Ticket queue is full. Cannot add more tickets.");
} else {
ticketQueue[rear] = ticket;
rear++;
size++;
System.out.println("Ticket #" + ticket + " successfully added to the queue.");
}
}
static void dequeue() {
if (size == 0) {
System.out.println("Ticket queue is empty. No tickets to dequeue.");
} else {
System.out.println("Support agent is resolving Ticket #" + ticketQueue[front]);
for (int i = 0; i < rear - 1; i++) {
ticketQueue[i] = ticketQueue[i + 1];
}
rear--;
size--;
}
}
static void displayQueue() {
if (size == 0) {
System.out.println("Ticket queue is empty.");
} else {
System.out.print("Current Ticket Queue: ");
for (int i = front; i < rear; i++) {
System.out.print(ticketQueue[i] + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the maximum number of tickets in the queue:");
int maxTickets = sc.nextInt();
new SupprtTicketSystem(maxTickets);
while (true) {
System.out.println("\nMenu:\n1. Add Ticket\n2. Resolve Ticket\n3. Display Queue\n4. Exit");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Enter the ticket number:");
sc.nextLine(); // consume the newline character left by nextInt()
String ticketNumber = sc.nextLine();
enqueue(ticketNumber);
break;
case 2:
dequeue();
break;
case 3:
displayQueue();
break;
case 4:
sc.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
}
}