Question: Given the Interface Code write a java class that implements this interface and show the working functionality in the main method: public interface CustomList {
Given the Interface Code write a java class that implements this interface and show the working functionality in the main method:
public interface CustomList{ /** * This method should add a new item into the CustomListand should * returntrueif it was successfully able to insert an item. * @param item the item to be added to theCustomList* @returntrueif item was successfully added,falseif the item was not successfully added (note: it should always be able to add an item to the list) */ boolean add (T item); /** * This method should add a new item into theCustomListat the * specified index (thus shuffling the other items to the right). If the index doesn't * yet exist, then you should throw anIndexOutOfBoundsException. * @param index the spot in the zero-based array where you'd like to insert your * new item * @param item the item that will be inserted into theCustomList* @returntruewhen the item is added * @throws IndexOutOfBoundsException */ boolean add (int index, T item) throws IndexOutOfBoundsException; /** * This method should return the size of theCustomList* based on the number of actual elements stored inside of theCustomList* @return anintrepresenting the number of elements stored in theCustomList*/ int getSize(); /** * This method will return the actual element from theCustomListbased on the * index that is passed in. * @param index represents the position in the backingObjectarray that we want to access * @return The element that is stored inside of theCustomListat the given index * @throws IndexOutOfBoundsException */ T get(int index) throws IndexOutOfBoundsException; /** * This method should remove an item from theCustomListat the * specified index. This will NOT leave an emptynullwhere the item * was removed, instead all other items to the right will be shuffled to the left. * @param index the index of the item to remove * @return the actual item that was removed from the list * @throws IndexOutOfBoundsException */ T remove(int index) throws IndexOutOfBoundsException; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
