Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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)

Java, Programming

  • Category:- Java
  • Reference No.:- M9131603
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Java

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As