0 1 4.5 ↑ front = 1 2 3.4 3 7.6 4 ↑ back = 4 xx, xx, xx..., xx Removing from queue. 5 6 7 8 numElement = 3 Write a main method/class that will ask the user for some information and display the results as shown below. Text in bold is user input. Queue 1.0 xx, xx, xx, ..., XX Queue empty. Final queue capacity is : XX 9 What is the initial capacity of the queue ? 5 How many random numbers ? 16 These 16 random numbers are being added to the queue:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

how does this work in java

Design a class called Queue that implements the queue data structure. A queue is
a data structure where elements are added at the end and removed from the
front (FIFO structure). Here is the UML diagram for the queue as well as the
contract description :
Queue
-que :double[]
-front :int
-back: int
-numElem :int
+Queue()
+Queue(capacity: int)
+empty():boolean
+full():boolean
+front(): double
+pop_front(): void
+push_back(value :double):void
+capacity(): int;
An array to store doubles in the queue
Tells us where the front of the queue is
Tells us where the back (tail) of queue is
Number of elements in the queue
Constructs an empty Queue of default capacity 16
Constructs an empty Queue with specified capacity
Returns true if queue is empty
Returns true if queue is full ( not needed here)
Returns element at front of queue
Removes element from front of queue
Adds element to end (tail) of queue
Returns capacity (ie length of array que)
Some things to consider when you are implementing this class :
1. both constructors are responsible for creating the array que. The second
constructor must make sure that capacity is >=0. If it is not then it will
create the array que with default size 16 ( just like the no-arg constructor).
This is a perfect place to use the this pointer. Also, remember to use a
named constant for the value 16.
2. Use the value of numElem to determine if the queue is empty.
3. front(), like top() in the stack class, does not remove the element from the
queue.
4. The queue should never fill up. If you try to add another double to the
queue and there is no room in que for that element, then allocate a new
array with twice the capacity of que, copy all elements in que to the new
array and make the new array your new que. The garbage collector will
Transcribed Image Text:Design a class called Queue that implements the queue data structure. A queue is a data structure where elements are added at the end and removed from the front (FIFO structure). Here is the UML diagram for the queue as well as the contract description : Queue -que :double[] -front :int -back: int -numElem :int +Queue() +Queue(capacity: int) +empty():boolean +full():boolean +front(): double +pop_front(): void +push_back(value :double):void +capacity(): int; An array to store doubles in the queue Tells us where the front of the queue is Tells us where the back (tail) of queue is Number of elements in the queue Constructs an empty Queue of default capacity 16 Constructs an empty Queue with specified capacity Returns true if queue is empty Returns true if queue is full ( not needed here) Returns element at front of queue Removes element from front of queue Adds element to end (tail) of queue Returns capacity (ie length of array que) Some things to consider when you are implementing this class : 1. both constructors are responsible for creating the array que. The second constructor must make sure that capacity is >=0. If it is not then it will create the array que with default size 16 ( just like the no-arg constructor). This is a perfect place to use the this pointer. Also, remember to use a named constant for the value 16. 2. Use the value of numElem to determine if the queue is empty. 3. front(), like top() in the stack class, does not remove the element from the queue. 4. The queue should never fill up. If you try to add another double to the queue and there is no room in que for that element, then allocate a new array with twice the capacity of que, copy all elements in que to the new array and make the new array your new que. The garbage collector will
0
1
4.5
↑
front = 1
2
3.4
3
7.6
st
XX, XX, XX..., XX
Removing from queue.
4
↑
back = 4
5
6
7
XX, XX, XX, ..., XX
Queue empty. Final queue capacity is : XX
8
numElement = 3
Write a main method/class that will ask the user for some information and display
the results as shown below. Text in bold is user input.
Queue 1.0
What is the initial capacity of the queue ? 5
How many random numbers ? 16
These 16 random numbers are being added to the queue:
9
Transcribed Image Text:0 1 4.5 ↑ front = 1 2 3.4 3 7.6 st XX, XX, XX..., XX Removing from queue. 4 ↑ back = 4 5 6 7 XX, XX, XX, ..., XX Queue empty. Final queue capacity is : XX 8 numElement = 3 Write a main method/class that will ask the user for some information and display the results as shown below. Text in bold is user input. Queue 1.0 What is the initial capacity of the queue ? 5 How many random numbers ? 16 These 16 random numbers are being added to the queue: 9
Expert Solution
steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education