In Java, create a program implementing the
functionalities of a standard queue in a class
called Queue3503. You will test the functionalities of
the Queue3503 class from the main() method of
the Main class. In a queue, first inserted items
are removed first and the last items are removed at the end
(imagine a line to buy tickets at a ticket counter).
Do NOT change your class name from "Main". The Main class should come first in your code. Your filename should be "Main.java".
The Queue3503 class will
contain:
a. An int[] data filed named elements to store the
int values in the queue.
b. An int data field named size that stores the
number of elements in the queue.
c. A no-arg constructor that creates a Queue object with default
capacity 0.
d. A constructor that takes an int argument representing the
capacity of the queue.
e. A method with signature enqueue(int v) that
adds the int element v into the queue.
f. A method with signature dequeue() that removes
and returns the first element of the
queue.
g. A method with signature empty() that returns
true if the queue is empty.
h. A method with signature getSize() that returns
the size of the queue (return type is hence
int)).
The queue class you develop should be tested using the
following steps: (In other words, your program named Main will
consist of the following)
a. Start your queue with an initial capacity of 8.
b. When the dequeue() method is called, an element from the queue
at the beginning of the queue must be removed.
c. The main() method in your Main class should consist
of statements to:
i. Create a queue object;
ii. Call enqueue() to insert twenty integers
(taken from the user) into the queue.
iii. After the above task is completed, include a for-loop that
will print out the contents of the queue.
d. After printing the queue filled with twenty
integers, call dequeue() repeatedly to remove the beginning
element of the queue.
e. Print the contents of the queue
after removing every fifth number.
f. For your reference, the execution of the Main
program is shown below. User inputs for populating the Queue is
shown in the first line. Next, your program outputs are
shown.
Your program MUST follow the sample output format
shown below.
Sample Run
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20
Initial content: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20
After removing 5 elements: 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20
After removing 5 elements: 11 12 13 14 15 16 17 18 19
20
After removing 5 elements: 16 17 18 19 20
Here is the implementation of Queue in Main.java :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner src = new
Scanner(System.in);
Queue3503 queueObj = new
Queue3503(8);
System.out.println("Please enter 20
elements");
for (int i = 0; i < 20; i++)
{
queueObj.enqueue(src.nextInt());
}
System.out.print("Initial
content: ");
for (int i = 0; i <
queueObj.getSize(); i++) {
System.out.print(queueObj.displayElement(i) + " ");
}
System.out.println();
int
counter=queueObj.getSize();
int counter2=0;
for(int i=0;i<counter;i++) {
queueObj.dequeue();
counter2++;
if(counter2%5==0
&& !queueObj.empty()) {
System.out.print("After removing 5 elements: ");
for(int j=0;j<queueObj.getSize();j++) {
System.out.print(queueObj.displayElement(j) + " ");
}
System.out.println();
}
}
}
}
class Queue3503 {
private int size;
int[] elements;
public Queue3503() {
size = 0;
elements = new int[size];
}
public Queue3503(int n) {
elements = new int[n];
}
void enqueue(int v) {
if (size < elements.length)
{
elements[size++]
= v;
} else {
int tempEle[] =
new int[elements.length + 5];
for (int i = 0;
i < size; i++) {
tempEle[i] = elements[i];
}
elements =
tempEle;
elements[size++]
= v;
}
}
public int dequeue() {
if (empty()) {
return -1;
} else {
int firstElement
= elements[0];
for (int i = 0;
i < size - 1; i++) {
elements[i] = elements[i + 1];
}
size--;
return
firstElement;
}
}
public boolean empty() {
return size == 0;
}
public int getSize() {
return size;
}
public int displayElement(int n) {
if (n < size)
return
elements[n];
return -1;
}
}
This is the output i have received after running the program:
Please enter 20 elements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Initial content: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20
After removing 5 elements: 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20
After removing 5 elements: 11 12 13 14 15 16 17 18 19 20
After removing 5 elements: 16 17 18 19 20
In Java, create a program implementing the functionalities of a standard queue in a class called Queue3503....
QUESTION 1: Queue Class: Write a Queue class using doubly-linked structure and implement the following functionalities. enqueue (inserts element to the end) dequeue (removes the front element and provides content) isEmpty (checks whether the Queue is empty or not) makeEmpty () peek (provides the element sitting at the top/front, but does not remove) print (prints all the elements from front to the end) reversePrint(prints all the elements from end to the front with the help of back pointers inside your...
java Create a Queue class based on java.util.LinkedList class. Your Queue class should have an enqueue(), dequeue(), peek(), and isEmpy() methods. Create a new Java Application that has the following methods: A method to randomly generate a number of elements between two given values and save them in a queue A method to print a queue (10 elements per line). The original queue should remain as is after the print A method to return the number of elements on the...
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...
Collect/finish the Java code (interface and the complete working
classes) from lecture slides for the for the following ADT:
3) Queue ADT that uses an array internally (call it AQueue)
Make sure you keep the same method names as in the slides
(automatic testing will be performed)! Make sure your classes
implement the corresponding interfaces. Put your classes in a
package called cse11. Try to make the code robust and try to use
generics.
The Queue ADT The Queue ADT...
Create a Java code that includes all the methods from the
Lecture slides following the ADTs
LECTURE SLIDES
Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....
Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue. The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...
Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the max-heap data structure using an integer array of 10 cells. (Do not use Java in-built PriorityQueue class.) [In a max-heap, the root node and the intermediate node vales are always greater than their children.] First, take 10 integer values from the user and insert them in the max-priority queue. Then print the elements of the queue. After that, delete two elements from the queue...
Design a Java class named StringQueue for storing strings of first names into a queue. The StringQueue.java class contains: * A String[] data field named names that stores the String values in the queue. * A private data field named size that stores the number of names in the queue. * A public static final data field named DEFAULT_CAPACITY = 10 for the array. * A private static data field named firstInitCtr that counts the number of names with the...