Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A) Consider the generic print() method, write a method that takes an array of E, where E must be Comparable or extend a type that

A) Consider the generic print() method, write a method that takes an array of E, where E must be Comparable or extend a type that is Comparable, and returns a reference to the greatest object in the array.  In this case, the greatest value is one for which compareTo() would return 0 or more for any other object in the array.  If there is more than one possible largest value (these would have to be equal to each other but greater than any other objects in the array), it does not matter which one you choose. 

B) Write a generic Java queue class (a plain queue, not a priority queue).  Call it GenericQueue, because the JDK already has an interface called Queue.  The class must be able to create a queue of objects of any reference type. the Stack, the GenericQueue should use an underlying ArrayList. 

Write these methods and any others you find useful:

enqueue() adds an E to the queue

peek() returns a reference to the object that has been in the queue the longest, without removing it from the queue

dequeue() returns the E that has been in the queue the longest, and removes it from the queue

contains(T t) returns true if the queue contains at least one object that is equal to t *in the sense that calling .equals() on the object with t the parameter returns true.* Otherwise contains returns false. 

size() and isEmpty() are obvious.

Step by Step Solution

3.39 Rating (146 Votes )

There are 3 Steps involved in it

Step: 1

Below are the Java implementations for both parts A and B Part A import javautil public class Generi... 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

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions

Question

2. Develop a preliminary question from a topic or issue.

Answered: 1 week ago