Question
1) Modify ListAPI. a) Download ListAPI.zip from Moodle and extract the NetBeans project folder ListAPI from the archive file. In NetBeans under the Project tab,
1) Modify ListAPI.
a) Download ListAPI.zip from Moodle and extract the NetBeans project folder ListAPI from the archive file. In NetBeans under the Project tab, right click on ListAPI and select Rename. In the Rename Project dialog box, rename the project p5_1_your-clid, select the Also Rename Project Folder option and click Rename.
b) Define the following method in MyList and implement it in MyAbstractList.
// Adds the elements in otherList to this list.
// Returns true if
// this list changed as a result of the call.
public boolean addAll(MyList
c) Add code to TestMyArrayList.java to demonstrate that this method works correctly. Display the modified list using a java.util.Iterator
I already did part a) but I am having trouble understanding what it is asking me to do #MyList
public interface MyList
/** Add a new element at the end of this list*/ public void add(E e); /**Add a new element at the specified index in this list*/ public void add(int index, E e);
/**Clear the list*/ public void clear();
/**Return true if this list contains the element*/ public boolean contains(E e);
/**Return the element from this list at the specified index*/ public E get(int index);
/**Return the index of the first matching element in this list. Return -1 if * no match.*/ public int indexOf(E e);
/**Return true if this list contains no elements*/ public boolean isEmpty();
/**Return the index of the last matching element in this list Return -1 if * no match.*/ public int lastIndexOf(E e);
/**Remove the first occurrence of the element o from this list. Shift any * subsequent elements to the left. Return true if the element is removed.*/ public boolean remove(E e);
/**Remove the element at the specified position in this list Shift any * subsequent elements to the left. Return the element that was removed from * the list.*/ public E remove(int index);
/**Replace the element at the specified position in this list with the * specified element and returns the new set.*/ public Object set(int index, E e);
/** Return the number of elements in this list */ public int size(); }
#MyAbsrtactList
public abstract class MyAbstractList
protected int size = 0; // The size of the list
/**Create a default list*/ protected MyAbstractList() { }
/**Create a list from an array of objects*/ protected MyAbstractList(E[] objects) { for (int i = 0; i < objects.length; i++) { add(objects[i]); } }
@Override /**Add a new element at the end of this list*/ public void add(E e) { add(size, e); }
@Override /**Return true if this list contains no elements*/ public boolean isEmpty() { return size == 0; }
@Override /**Return the number of elements in this list*/ public int size() { return size; }
@Override /**Remove the first occurrence of the element e from this list. Shift any * subsequent elements to the left. Return true if the element is removed. */ public boolean remove(E e) { if (indexOf(e) >= 0) { remove(indexOf(e)); return true; } else { return false; } } public boolean addAll(MyList #TestMyArrayList public class TestMyArrayList { public TestMyArrayList() { // Create a list MyList // Add elements to the list list.add("America"); // Add it to the list System.out.println("(1) " + list); list.add(0,"Canada"); // Add it to the beginning of the list System.out.println("(2) " + list); list.add("Russia"); // Add it to the end of the list System.out.println("(3) " + list); list.add("France"); // Add it to the end of the list System.out.println("(4) " + list); list.add(2, "Germany"); // Add it to the list at index 2 System.out.println("(5) " + list); list.add(5, "Norway"); // Add it to the list at index 5 System.out.println("(6) " + list); // Remove elements from the list list.remove("Canada"); // Same as list.remove(0) in this case System.out.println("(7) " + list); list.remove(2); // Remove the element at index 2 System.out.println("(8) " + list); list.remove(list.size() - 1); // Remove the last element System.out.print("(9) " + list + " (10) "); for (String s : list) { System.out.print(s.toUpperCase() + " "); } } }
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