Question
Programming:
Your main() method should be interactive (menu driven) and should give the following options to a
user:
i) Insert an item to the queue (at rear)
ii) Delete an item from the queue (from front)
iii) Display the item at front
iv) Display the item at rear
v) Display total number of items currently present in the queue
vi) Print the items currently present in the queue
vii) Quit
The program should start with the menu and the user should be able to choose any option from the menu. The menu should keep coming back, after completing each user choice, until the user selects ‘Quit’ option. Also, include proper error checking (for example, when someone tries to delete item from an empty queue, or tries to display items of an empty queue) with appropriate message(s).
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Scanner;public class LinkedlistQue {
/**
* private class holds data and connection to other item in the list
*/
private class Node{
int item; // data
Node next; // connector
/**
* constructor
* @param item
* @param next
*/
public Node(int item, Node next) {
this.item = item;
this.next = next;
}
};
private Node front; // front reference
private Node rear; // rear reference
private int total;// number of item in queue...