Question: import java.util.Arrays; public class QueueConsole { private String[] queueArray; private int queueSize; private int front, rear,numberOfItems = 0; QueueConsole(int size){ queueSize = size; queueArray =

import java.util.Arrays;

public class QueueConsole {

private String[] queueArray;

private int queueSize;

private int front, rear,numberOfItems = 0;

QueueConsole(int size){

queueSize = size;

queueArray = new String[size];

Arrays.fill(queueArray,"-1");

}

public void insert(String input){

if(numberOfItems <= queueSize)

{

queueArray[rear] = input;

rear++;

numberOfItems++;

System.out.println("PUSH " + input + " was inserted into the queue.");

}

else{

System.out.println("Sorry but the queue is full.");

}

}

//insert elements using priority options (priority queues)

//optional whether use simple insert or priority insert function

public void priorityInsert(String input) {

int i;

if(numberOfItems == 0) {

insert(input);

}

else {

for(i=numberOfItems-1; i>=0; i--){

if(Integer.parseInt(input) > Integer.parseInt(queueArray[i])){

queueArray[i+1] = queueArray[i];

} else break;

}

queueArray[i+1] = input;

rear++;

numberOfItems++;

}

}

public void remove(){

if(numberOfItems > 0) {

System.out.println("REMOVE " + queueArray[front] + " was removed from the queue.");

queueArray[front] = "-1";

front++;

numberOfItems--;

} else

{

System.out.println("Sorry but the queue is empty.");

}

}

public void peek(){

System.out.println("The first element is " +queueArray[front]);

}

public void displayTheQueue(){

for(int i=0; i<45;i++) { System.out.print("=");} System.out.print(" ");

for(int i = 0; i < 10; i++){

System.out.print("| " + queueArray[i]);

}

System.out.print("| ");

for(int i=0; i<45;i++) { System.out.print("=");} System.out.print(" ");

}

public static void main(String[] args) {

QueueConsole thequeue = new QueueConsole(10);

//priority insert - priority queues

//thequeue.priorityInsert("10");

//thequeue.priorityInsert("19");

//thequeue.priorityInsert("15");

//thequeue.priorityInsert("11");

thequeue.insert("1");

thequeue.insert("10");

thequeue.insert("20");

thequeue.insert("30");

thequeue.insert("40");

thequeue.priorityInsert("500");

thequeue.priorityInsert("1000");

thequeue.priorityInsert("1500");

thequeue.priorityInsert("2500");

thequeue.displayTheQueue();

thequeue.peek();

thequeue.remove();

thequeue.displayTheQueue();

thequeue.peek();

}

}

From the code above. Provide a menu of selection from the given problem.

Use Joption for the selection pls. java language

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!