Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

~~~~~~~~~~~~~~~~/////////////////////////////////~~~~~~~~~~~~~~~~~~~~~~~~~ Write

ID: 3617490 • Letter: #

Question

~~~~~~~~~~~~~~~~/////////////////////////////////~~~~~~~~~~~~~~~~~~~~~~~~~

Writea class to implement the following interface, which is for a list with alimited range of values. For example, the list could contain only the Strings"excellent", "good", "fair" or "poor".A possible list with these values would be as follows:
good, fair, good, excellent, poor, fair. The range of values should beobtained by passing an array of objects as a parameter to the constructor. Thefields of the class should be an array of possible values, an array of intsthat are indices into the array of possible values, and a size.

public interface LimitedListInterface <Textends Comparable<? super T>> {

//Add an element at the end of the list

public void add(T elt);

//Add an element at the specified index,counting from 0.

//Return true or false to indicate success.

public boolean add(T elt, int idx);

//Return the element at the given index, ornull if there

//is no such element.

public T find(int idx);

//Return the index of the given element, or-1 if not found.

public int find(T elt);

//Remove the element at the given index andreturn true,

//or return false if there is no suchelement.

public boolean remove(int idx);

//Remove the given element and return true,

//or return false if there is no suchelement.

public boolean remove(T elt);

//Print out the list, separated by commas.

//Note that you should print the elements,not the indices.

public void print();

}

Hints:The following private methods would be helpful.

// return the index of the element in thearray of possible values

private int findIdx(T elt);

//resize and copy the array if necessary

private void ensureCapacity(intrequestedSize);

Explanation / Answer

x.Xce="Courier New">import java.util.*; class LimitedList