Java the goal is to create a list class that uses an array to implement the...

80.2K

Verified Solution

Question

Programming

Java the goal is to create a list class that uses an array toimplement the interface below. I'm having trouble figuring out theremove(T element) and set(int index, T element). I haven't addedany custom methods other than a simple expand method that doublesthe size by 2. I would prefer it if you did not use any othercustom methods. Please use Java Generics, Thank you.

import java.util.*;

/**
* Interface for an Iterable, Indexed, Unsorted List ADT.
* Iterators and ListIterators provided by the list arerequired
* to be \"fail-fast\" and throw ConcurrentModificationExceptionif
* the iterator detects any change to the list from anothersource.
* Note: \"Unsorted\" only means that it is not inherentlymaintained
* in a sorted order. It may or may not be sorted.
*
* @author CS 221
*
* @param - class of objects stored in the list
*/
public interface IndexedUnsortedList extends Iterable
{
/**
* Adds the specified element to the front of this list.
*
* @param element the element to be added to the front of thislist
*/
public void addToFront(T element);

/**
* Adds the specified element to the rear of this list.
*
* @param element the element to be added to the rear of thislist
*/
public void addToRear(T element);

/**
* Adds the specified element to the rear of this list.
*
* @param element the element to be added to the rear of thelist
*/
public void add(T element);

/**
* Adds the specified element after the specified target.
*
* @param element the element to be added after the target
* @param target the target is the item that the element will beadded after
* @throws NoSuchElementException if target element is not in thislist
*/
public void addAfter(T element, T target);
  
/**
* Inserts the specified element at the specified index.
*
* @param index the index into the array to which the element is tobe inserted.
* @param element the element to be inserted into the array
* @throws IndexOutOfBoundsException if the index is out of range(index < 0 || index > size)
*/
public void add(int index, T element);

/**
* Removes and returns the first element from this list.
*
* @return the first element from this list
* @throws NoSuchElementException if list contains no elements
*/
public T removeFirst();

/**
* Removes and returns the last element from this list.
*
* @return the last element from this list
* @throws NoSuchElementException if list contains no elements
*/
public T removeLast();

/**
* Removes and returns the first element from the list matching thespecified element.
*
* @param element the element to be removed from the list
* @return removed element
* @throws NoSuchElementException if element is not in thislist
*/
public T remove(T element);

/**
* Removes and returns the element at the specified index.
*
* @param index the index of the element to be retrieved
* @return the element at the given index
* @throws IndexOutOfBoundsException if the index is out of range(index < 0 || index >= size)
*/
public T remove(int index);
  
/**
* Replace the element at the specified index with the givenelement.
*
* @param index the index of the element to replace
* @param element the replacement element to be set into thelist
* @throws IndexOutOfBoundsException if the index is out of range(index < 0 || index >= size)
*/
public void set(int index, T element);

/**
* Returns a reference to the element at the specified index.
*
* @param index the index to which the reference is to be retrievedfrom
* @return the element at the specified index
* @throws IndexOutOfBoundsException if the index is out of range(index < 0 || index >= size)
*/
public T get(int index);

/**
* Returns the index of the first element from the list matching thespecified element.
*
* @param element the element for the index is to be retrieved
* @return the integer index for this element or -1 if element isnot in the list
*/
public int indexOf(T element);

/**
* Returns a reference to the first element in this list.
*
* @return a reference to the first element in this list
* @throws NoSuchElementException if list contains no elements
*/
public T first();

/**
* Returns a reference to the last element in this list.
*
* @return a reference to the last element in this list
* @throws NoSuchElementException if list contains no elements
*/
public T last();

/**
* Returns true if this list contains the specified targetelement.
*
* @param target the target that is being sought in the list
* @return true if the list contains this element, else false
*/
public boolean contains(T target);

/**
* Returns true if this list contains no elements.
*
* @return true if this list contains no elements
*/
public boolean isEmpty();

/**
* Returns the number of elements in this list.
*
* @return the integer representation of number of elements in thislist
*/
public int size();

/**
* Returns a string representation of this list.
*
* @return a string representation of this list
*/
public String toString();

/**
* Returns an Iterator for the elements in this list.
*
* @return an Iterator over the elements in this list
*/
public Iterator iterator();

/**
* Returns a ListIterator for the elements in this list.
*
* @return a ListIterator over the elements in this list
*
* @throws UnsupportedOperationException if not implemented
*/
public ListIterator listIterator();

/**
* Returns a ListIterator for the elements in this list, with
* the iterator positioned before the specified index.
*
* @return a ListIterator over the elements in this list
*
* @throws UnsupportedOperationException if not implemented
*/
public ListIterator listIterator(int startingIndex);
}

Answer & Explanation Solved by verified expert
4.1 Ratings (595 Votes)
Code for IndexedUnsortedListjava import javautil Interface for an Iterable Indexed Unsorted List ADT Iterators and ListIterators provided by the list are required to be failfast and throw ConcurrentModificationException if the iterator detects any change to the list from another source Note Unsorted only means that it is not inherently maintained in a sorted order It may or may not be sorted author CS 221 param class of objects stored in the list public interface IndexedUnsortedList extends Iterable Adds the specified element to the front of this list param element the element to be added to the front of this list public void addToFrontT element Adds the specified element to the rear of this list param element the element to be added to the rear of this list public void addToRearT element Adds the specified element to the rear of this list param element the element to be added to the rear of the list public void addT element Adds the    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students