******IN JAVA******** I need the following interface implemented accordingly. It is a linked list. The interface can...

90.2K

Verified Solution

Question

Programming

******IN JAVA********

I need the following interface implemented accordingly.It is a linked list. The interface can be found below:

List.java

public interface List extends Iterable {  /**   * Insert an element at a specified location.   * @param index   * @param obj   * @throws IndexOutOfBoundsException   */  public void add(int index, T obj);    /**   * Append an object to the end of the list.   * @param obj   */  public boolean add(T obj);    public void clear();  public boolean contains(T obj);    /**   * If obj is in the list, return the   * index of the first occurrence.   * Otherwise, return -1.   * @param obj   * @return   */  public int indexOf(T obj);    public boolean isEmpty();    public int lastIndexOf(T obj);    /**   * Get and return the value stored at the index.   *   * @param index   * @return   * @throws IndexOutOfBoundsException   */  public T get(int index);      public T remove(int index);  public boolean remove(T obj);    /**   * Update the value in the list at the specified index.   * Return the old value   * @throws IndexOutOfBoundsException   * @param index   * @param obj   * @return   */  public T set(int index, T obj);    public int size();    public Object[] toArray();}

I also need the following driver modified so that itworks with the implementation:

ListDriver.java

import java.util.Iterator;public class ListDriver {  /**   * @param args the command line arguments   */  public static void main(String[] args) {    int i = 0;    List names = new AList<>(5);    names.add(\"Alice\");    names.add(\"Bob\");    names.add(\"Carol\");    names.add(1, \"Eve\");    names.add(\"Eve\");    for (String name : names)      System.out.println((i++) + \":\" + name);    i=0;    System.out.println(\"Size (should be 5): \" + names.size());    System.out.println(\"IndexOf(Eve) (should be 1): \" + names.indexOf(\"Eve\"));    System.out.println(\"LastIndexOf(Eve) (should be 4): \" + names.lastIndexOf(\"Eve\"));    System.out.println(\"Remove Eve (should be true):\" + names.remove(\"Eve\"));    System.out.println(\"Size (should be 4): \" + names.size());    System.out.println(\"IndexOf(Eve) (should be 3): \" + names.indexOf(\"Eve\"));    System.out.println(\"LastIndexOf(Eve) (should be 3): \" + names.lastIndexOf(\"Eve\"));    for (String name : names)      System.out.println((i++) + \":\" + name);    i=0;    System.out.println(\"Remove Eve (should be true):\" + names.remove(\"Eve\"));    System.out.println(\"Size (should be 3): \" + names.size());    System.out.println(\"IndexOf(Eve) (should be -1): \" + names.indexOf(\"Eve\"));    System.out.println(\"LastIndexOf(Eve) (should be -1): \" + names.lastIndexOf(\"Eve\"));    System.out.println(\"Size (should be 3): \" + names.size());    System.out.println(\"Remove 0 (should be Alice): \" + names.remove(0));    System.out.println(\"Size (should be 2): \" + names.size());    names.add(0, \"Alice\");    names.add(1, \"Eve\");    names.add(\"Eve\");    names.add(1, \"Eve\");    names.add(\"Eve\");    names.add(1, \"Eve\");    names.add(names.indexOf(\"Carol\"), \"Eve\");    names.add(0, \"Eve\");    names.add(\"Eve\");    System.out.println(\"Size: \" + names.size());    for (String name : names)      System.out.println((i++) + \":\" + name);    i=0;    System.out.println(\"Remove all instances of Eve using iterator... \");    Iterator it = names.iterator();    while(it.hasNext()) {      if (it.next().equals(\"Eve\"))        it.remove();    }    for (String name : names)      System.out.println((i++) + \":\" + name);    i=0;    System.out.println(\"Testing clear\");    names.clear();    System.out.println(\"Size (should be 0): \" + names.size());      }  }

Thanks in advance. Will upvote!

Answer & Explanation Solved by verified expert
4.2 Ratings (835 Votes)
Listjavapublic interface List extends Iterable Insert an element at a specified location param index param obj throws IndexOutOfBoundsExceptionpublic void addint index T obj Append an object to the end of the list param objpublic boolean addT objpublic void clearpublic boolean containsT obj If obj is in the list return the index of the first occurrence Otherwise return 1 param obj returnpublic int indexOfT objpublic boolean isEmptypublic int lastIndexOfT obj Get and return the value stored at the index param index return throws IndexOutOfBoundsExceptionpublic T getint indexpublic T removeint indexpublic boolean removeT obj Update the value in the list at the specified index Return the old value throws IndexOutOfBoundsException param index param obj returnpublic T setint index T objpublic int sizepublic Object toArrayend of Listjava Nodejava Java class to represent the Node of 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