Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java language, answer this step by step with comments. Q 06. (8 points) Design a class named Queue for storing integers. Like a stack,
In java language, answer this step by step with comments.
Q 06. (8 points) Design a class named Queue for storing integers. Like a stack, a queue holds clements. In a stack, the elements are retrieved in a last-in first-out fashion. In a queue, the elements are retrieved in a first-in first-out fashion. The class contains: - An int[] data field named elements that stores the int values in the queue. - A data field named size that stores the number of elements in the queue. - A constructor that creates a Queue object with default capacity 8. - The method enqueue(int v) that adds v into the queue. - The method dequeue() that removes and returns the element from the queue. - The method emptyO that returns true if the queue is empty. - The method getSize() that returns the size of the queue. Implement the class with the initial array size set to 8 . The array size will be doubled once the number of the elements exceeds the size. After an element is removed from the beginning of the array, you need to shift all elements in the array one position to the left. Write a test program that adds 20 numbers from 1 to 20 into the queue then removes these numbers and displays them. Here is a sample run after adding 1 to 20 to the queue and removed them: 01234567891011121314151617181920 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started