Question: Consider the following generic queue interface: interface MyQueue { // return the top of the queue element or throw NoSuchElementException if empty E head(); //

Consider the following generic queue interface:

interface MyQueue {

// return the top of the queue element or throw NoSuchElementException

if empty

E head();

// remove and return the top of the queue element or throw

NoSuchElementException if empty

E dequeue();

// add an element to the queue

void enqueue(E e);

// returns the size of the queue

int size();

// returns true if the queue is empty

boolean isEmpty();

// add elements to this queue from a collection c of E references:

void addAll(Collection c);

}

a) Use the Adapter pattern to design a generic queue class called

LQueue that implements

interface MyQueue and that uses a LinkedList object to stores the

queue elements.

Write the UML class diagram for the pattern.

Identify the pattern roles (e.g. "adapter", "adaptee") with UML notes on

the class diagram.

b) Implement class LQueue in Java.

Write correct contracts for each method. (Notice that

NoSuchElementException is not a checked

exception, but you could put it in the function signature.)

c) Write a class QueueTest with a main(...) method that tests all 6

methods from class LQueue.

There is no need of junit unit tests. Use hardcoded objects.

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!