
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
how would you do this 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](https://content.bartleby.com/qna-images/question/66301e59-a86d-47c0-9dd8-21e24614422a/8f0720f5-938f-41f0-99ff-5885ff2b7fc1/1h6ig6_thumbnail.png)
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
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 3 images

Knowledge Booster
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.Similar questions
- JavaProblem 2-4 Pennies ProblemProblem 2-4. Pennies Problem. Here’s an old problem. Today, I’ll give you a penny. Tomorrow, I’ll give you two pennies. I’ll keep doubling the amount I’ll give you for 30 days. How much will you have at the end of the month (better use a long integer type to keep track)?arrow_forwardPlease solve this in java, using the Gui system(Jframe, Jpanel, etc) from java, not java fx thanks.arrow_forwardMake a java airline reservation system. Things the program should have: - Main menu(options to cancel, book and reschedule flights) - Use things like constructors, array lists, etc. - System.out.println your final ticket with the date of the flight, number and airline.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education