Question
I have only included part of the assignment as I only want enough shown to ensure I am on the right track(as i believe i
I have only included part of the assignment as I only want enough shown to ensure I am on the right track(as i believe i am). If an important part is missing, please let me know and I will add. I am to implement the interface MyList with the abstract class MyAbstractL. Then extend MyAbstractL to MyArrayLIst. The two Class are listed first with the methods to be included in them. The Javadoc is below that.
Abstract class MyAbstractL
addLast(E e) clear() getFirst() removeLast() setLast(E e) size()
Methods in abstract can not access array. Can only call methods in interface
Concrete class MyArrayList
MyArrayList() MyArrayList(E[] eArr) add(int i, E e) capacity() ensureCapacity(int newCap) firstIndexOf(E e) get(int i) set(int i, E e)
Generic Interface to be implemented.
* @param
/** * Adds the given element at the given index position i. * * @param i index position where the given element will be added * @param e element to be added at the given index position * @throws IndexOutOfBoundsException if i < 0 or i > size() Note: that * it is ok for i to equal size() */ public void add(int i, E e) throws IndexOutOfBoundsException;
/** * Adds the given element to the end of this list. * * @param e element to be added to the end of this list */ public void addLast(E e);
/** * Removes all list elements, if any exist */ public void clear();
/** * Returns true if the specified element in in this list, returns false * otherwise. * * @param e element that is being searched for * @return ture if the specified element is in this list, returns false * otherwise */ public boolean contains(E e);
/** * Returns the index of the first occurrence of the specified element, -1 if * the element is not in this list * * @param e element being searched for * @return index of the first occurrence of the specified element, returns * -1 if the element is not in this list */ public int firstIndexOf(E e);
/** * Returns the element at the given index position. * * @param i index of the list element to return * @return the element located at the given index position * @throws IndexOutOfBoundsException if i < 0 or i ≥ size() */ public E get(int i) throws IndexOutOfBoundsException;
/** * Returns the first element in this list. * * @return the first element in this list. * @throws IllegalStateException if list is empty. */ public E getFirst() throws IllegalStateException;
/** * Removes and returns the last element in this list. * * @return last element in this list * @throws IllegalStateException if this list is empty. */ public E removeLast() throws IllegalStateException;
/** * Replaces the element at the given index position with the given element * and returns the old element. * * @param i index of the element to be replaced * @param e new element that will be stored at the given index position * @return element that was previously stored at the given index position * @throws IndexOutOfBoundsException if i < 0 or i ≥ size() */ public E set(int i, E e) throws IndexOutOfBoundsException;
/** * Replaces the last element with the given element and returns the old * element. * * @param e new element that will be stored as the last list element * @return element that was previously stored as the last list element * @throws IllegalStateException if list is empty. */ public E setLast(E e) throws IllegalStateException;
/** * Returns the number of elements in this list. * * @return number of elements in this list */ public int size();
}
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