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 extends E> c);
}
a) Use the Adapter pattern to design a generic queue class called
LQueue
interface MyQueue
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started