1 gqueuea queue is an ordered collection of items in which

Assignment Help JAVA Programming
Reference no: EM13347239

1: GQueue

A queue is an ordered collection of items in which the removal of items is restricted to the FIFO ( rst in rst out) principle. That is, the rst item added to the queue will be the rst
one removed, the second added will be the second removed, etc.

When you are standing in line waiting for a bank teller, you are in a queue of people. The rst in the line is the rst to be served. The next in line is the second to be served (or removed from the queue). Using this understanding of a queue, we will say that items added to a queue are added to the back of the queue (i.e., you go to the back of the line when you add yourself to the line). The word for adding an element to a queue is enqueue. When we remove an item for a queue, we remove it from the front of the queue (i.e., if you are next to be served in the line, you are at the front of the line). The word for removing an item from
a queue is dequeue.

Recall that we used top for the place where we add and remove elements from a Stack. While this word has a natural meaning to us, it should reveal how the Stack ADT is imple-
mented in code. Similarly, we use back and front for the two \ends" of a queue, but these words do not necessarily relate to the actual data structures used to implement a Queue
ADT.

In this assignment, you will write code for a generic Queue ADT, which we will call GQueue. Here is the ADT for a Queue:

Queue
data                                                               operations
an ordered collection of items                      - add an item to the collection
(need not be unique)                                   - remove an item from the collection using FIFO principle
                                                                    - ask if the collection is empty or not
                                                                    - ask what the next item removed would be
                                                                    - ask how many items are in the collection

Your Java class must use generics for the data type of the elements in the queue. Your class must implement the Comparable interface.
Your generic Queue implementation should have the following public methods and constructors (with appropriate return and input argument types):

public boolean enqueue(...)
// purpose: add an item to the back of the queue if possible
--> // preconditions: item added must be same type as specified when this was created
// postconditions: if size of the queue is < capacity of the queue
//                          adds the item to the queue,
//                          the size of the queue is incremented by 1,
//                          returns true
//                          otherwise (the size of the queue = capacity of the queue)
//                          return false and do nothing
dequeue()
// purpose: retrieve the item from the front of the queue
// preconditions: the queue must be non-empty
// postconditions: returns the item at the front of the queue
//                          that item is removed from the queue
//                          the size of the queue is decremented by 1
isEmpty()
// purpose: asks if the queue is empty or not
// postconditions: returns true if the queue is empty
//                          returns false if there is 1 or more items in the queue
size()
// purpose: returns the size of the queue
// postconditions: returns the number of items in the queue
peek()
// purpose: ask what item is at the front of the queue
// preconditions: the queue must be non-empty
// postconditions: returns the item at the front of the queue
//                          (does not remove the item)
//                          (does not decrement size)
-> isFull()
// purpose: ask if there is room to add an item to the queue
// postconditions: returns true if the queue is full (it has reached its capacity)
//                          returns false if there is room to add at least one more item
GQueue(int n)
// purpose: create an empty queue with capacity n
// preconditions: none
// postconditions: creates an empty queue with capacity n
//                          (the queue can store up to n items at any given time)

Reference no: EM13347239

Questions Cloud

Problem 1at the beginning of 20x2 dahl ltd acquired 8 of : problem 1at the beginning of 20x2 dahl ltd. acquired 8 of the outstanding common shares of tippy ltd. for 400000.nbsp
1 trace the development of the industrial revolution in : 1. trace the development of the industrial revolution in early 19th century america. how did life for the american
Question 1an airline was interested in measuring the length : question 1an airline was interested in measuring the length of time customers have to wait in the queue prior to
1 evaluate the sequence generated by each of the following : 1. evaluate the sequence generated by each of the following generating functions.2. for each of the subsequent
1 gqueuea queue is an ordered collection of items in which : 1 gqueuea queue is an ordered collection of items in which the removal of items is restricted to the fifo rst in rst
Question 1the current selling price is 90 per unit and : question 1the current selling price is 90 per unit and variable expenses are 60 per unit. fixed expenses are 810000 per
Question onea the probability that a bomber sets a target : question one.a the probability that a bomber sets a target on a bombing mission is 0.70 three bombers are sent to bomb
Toms pizza sells for 500 ea and serves an average of 425 : toms pizza sells for 5.00 ea and serves an average of 425 customers per week. during a recent sale tom lowered the
1 explain the differences between our specifications of the : 1. explain the differences between our specifications of the sorted list adt and the binary search tree adt.2. define a

Reviews

Write a Review

JAVA Programming Questions & Answers

  Design a program that asks the user to enter a series of 20

Number Analysis Program: Design a program that asks the user to enter a series of 20 numbers

  Write a program that takes 10 values representin

Using a loop, write a program that takes 10 values representin exam grades (between 0 and 100) from the keyboard and outputs the minimum value, maximum value, and average value of all the values entered. Your program should not accept less than 0 ..

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Add a button that will read the text fields

Create a GUI with two text fields for inputting the dimensions of a rectangle. Identify these two text fields as Length and Width with labels. Add a button that will read the text fields and cause the GUI to display the area and perimeter of the r..

  Design a single class that expresses the commonality

Design a single class that expresses the commonality of these concepts.

  Application for an animal-fur trimming service

Create an application for an animal-fur trimming service. Write the code for the application. Prompt the user to indicate how many animals. Display the total fee for one year. Be pleasant in your output as it will be expensive.

  Consider a company that wants to keep track of its employees

Consider a company that wants to keep track of its employees, their positions and their telephone numbers. Your development team has developed a simple prototype using the Java code found in EmployeeDirectory.zip.

  Returns the object with the largest measure

public static Measurable maximum(Measurable[] objects)that returns the object with the largest measure. Use that method to determine the country with the largest area from an array of

  Write java program to print price of table-furniture company

Write down the Java program for furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate the price of table produced with chosen wood.

  Write a test program that obtains from the user

Write a test program that obtains from the user the items to store in two sets A and B, and displays the union A u B, the inter- section A n B, and the dierence A \ B. The data type of the items is your choice. ( you can only store objects.)

  Produce a design document

You will design and deliver a website foes fictional client part-1 Website Design Document and produce a design document

  Create an array of date objects

Create an array of Date objects of size 4. Initialize the array by using a loop. In the loop, use the Scanner.nextLine() method to input a date as a string, convert it to a date by using the toDate() method, and assign the result to an element in ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd