Question: You are tasked with implementing a Java program to manage a queue of students in a classroom. The queue is represented using a linked list,
You are tasked with implementing a Java program to manage a queue of students in a classroom. The queue is represented using a linked list, where each node contains the name of a student. The program should allow the following operations:
Enqueue: Add a new student to the end of the queue.
Dequeue: Remove the student at the front of the queue.
Print: Display all student names currently in the queue.
Write a Java program that implements the above operations using a linked list.
Your program should:
Implement a Student class with fields for the name of the student and a next pointer to the next student
Implement a ClassroomQueue class that manages the linked list of students and includes methods for enqueue, dequeue, and print operations.
Use the Scanner class to take input from the user for enqueueing, dequeuing, and printing the queue.
Handle edge cases such as attempting to dequeue from an empty queue.
EXAMPLE OUTPUT
Choose an operation:
Enqueue
Dequeue
Print Queue
Exit
Enter your choice:
Enter student name: Alice
Queue: Alice
Choose an operation:
Enqueue
Dequeue
Print Queue
Exit
Enter your choice:
Enter student name: Bob
Queue: Alice Bob
Choose an operation:
Enqueue
Dequeue
Print Queue
Exit
Enter your choice:
Dequeued: Alice
Queue: Bob
Choose an operation:
Enqueue
Dequeue
Print Queue
Exit
Enter your choice:
Queue: Bob
Choose an operation:
Enqueue
Dequeue
Print Queue
Exit
Enter your choice:
Exiting program...
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
