Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor

public class Queue {

private int maxSize;

private long[] queArray;

private int front;

private int rear;

private int nItems;

//--------------------------------------------------------------

public Queue(int s) // constructor

{

maxSize = s;

queArray = new long[maxSize];

front = 0;

rear = -1;

nItems = 0;

}

//--------------------------------------------------------------

public void insert(long j) // put item at rear of queue

{

if(rear == maxSize-1)

rear = -1;

queArray[++rear] = j;

nItems++;

// deal with wraparound

// increment rear and insert

// one more item

}

//--------------------------------------------------------------

public long remove() { // take item from front of queue

long temp = queArray[front++]; // get value and incr front

if(front == maxSize) // deal with wraparound

front = 0;

nItems--; // one less item

return temp;

}

//--------------------------------------------------------------

public long peekFront() // peek at front of queue

{

return queArray[front]; }

//--------------------------------------------------------------

public boolean isEmpty() // true if queue is empty

{

return (nItems==0); }

//--------------------------------------------------------------

public boolean isFull() // true if queue is full

{

return (nItems==maxSize); }

//--------------------------------------------------------------

public int size() // number of items in queue

{

return nItems;

}

}

Using Queue algorithm as shown in the code above, create a program that is capable to store 10 numbers. The program should accept a number entered from the keyboard. The user can add a number while the array is not yet full, once the array is full the program should show message that the array is full and the user can only add another number if the user will remove a number from the array. The program should also inform the user if the array is empty.

Note: The program should have a menu as shown below and include all necessary error checking for this program.

Menu [1] Insert Number [2] Remove Number [3] Display content of the array [4] Exit Enter your choice:

note : use the same class and if statment

use java eclipse

do not use hard code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

Why is the activity of prototyping so important?

Answered: 1 week ago

Question

7. What is coaching? Is there only one type of coaching? Explain.

Answered: 1 week ago