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

I just need a java method that complies withe the JavaDocs above the method name

ID: 3596279 • Letter: I

Question

I just need a java method that complies withe the JavaDocs above the method name. Using a arraylist.

public class WorkAheadQueue<T> implements WorkAheadQueueADT<T> {
    private LinearNode<T> front;
    private LinearNode<T> back;
    private int numNodes;
    private ArrayList<LinearNode<T>> frontFive;

Returns (without removing) the element that is at place x in the queue. Precondition: x must be less than 5, x must be less than size Note: indexing from 0:0-front element, 1second element, etc. @return the element at the front of the queue throws EmptyCollectionException if the queue is empty @throws InvalidArgumentException if x 4, orx size of collection @param X the specified index of the element to return public T first(int x) throws EmptyCollectionException, InvalidArgumentException:

Explanation / Answer

Please find my implementation.

Please let me know in case of any issue.

public T first(int x) throws EmptyCollectionException, InvalidArgumentException {

      

       if( x > 4 || x > numNodes) {

           throw new InvalidArgumentException();

       }

       return frontFive.get(x);

   }