Question: java program Queue We will be implementing two different types of queues and running them on the same simulator. Since both are queues they must

java program

Queue

We will be implementing two different types of queues and running them on the same simulator. Since both are queues they must have many methods in common. It is important that we inform Java of this fact as otherwise we would have to write a separate simulator for each queue. To do this we need to create an interface for queues.

Interface Queue Queues are line ups, e.g. a line up to get a ticket. They have the property that elements are removed from the queue in the same order that they were put into the queue, e.g. the first person in a line is the first person to be served

All queues have four common methods: isEmpty, enqueue, dequeue and clear. The implementations of each of these methods is dependant on the type of queue which is why we must use an interface. However, below is a description of what each method is supposed to do

isEmpty checks to see if the queue contains an elements. It returns true is the queue is empty and false otherwise.

enqueue adds an element to the back queue, e.g. when a person enters a line they start go to the back and wait their turn. Since our queues store objects of class Job, enqueue should take in (as a parameter) an object of class Job and add it to the back of the queue

dequeue removes an element from the front of the queue, e.g. the person at the front of the line gets served. Since our queues store objects of class Job, dequeue removes the front Job from the queue and returns it. clear removes all the elements from queue, emptying it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!