Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

In most cases, medication is prescribed by physicians.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago