Question: Lab 3 When finished upload the following files : ArrayList.java source file LinkedList.java source file LabDeleteListIterator.java source file RefListIterator.java source file ArrayListIterator.java source file Output
Lab 3
When finished upload the following files
: ArrayList.java source file
LinkedList.java source file
LabDeleteListIterator.java source file
RefListIterator.java source file
ArrayListIterator.java source file
Output produced by all three Drivers.
1. Define an equals(Object) method for Lists. Two lists are equal if and only if they store the same values (in the same order). An ArrayList can be equal to a LinkedList. You can put the API in your List interface:
/** @return true only if the parameter obj is a List and contains the same
elements
* (in the same sequence) as this List.
*/
boolean equals (Object obj);
You may use the instanceof operator to determine whether the parameter is a List. If so, cast it as a List, storing a
reference to it in a local variable. Your solution should be efficient. Test your solution with DriverLabEquals.
Hints:
First compare the sizes of the two lists. If they have different sizes, they could not be equal.
Use Iterators.
2. Define a class named Student in your listDriver package. Every Student has a name, which is a String,
and every Student has an id number, which is an int. Two Students are considered equal if they have the same id
number, even if they have different names. Also include methods getName() and getID() in that class. In the driver,
LabDeleteListIterator, there is a method which needs to be completed. Its name is deleteFirstOfDup(). It is
supposed to search a List named roster for the first pair of neighboring Students which are equal; then it should
delete the first Student of that pair from the List.
You may give the main method a parameter, but do not make other changes to the driver.
Hint: Use a ListIterator.
3. Include an add(E) method in your ListIterator interface. It should add a value to the List
just prior to the implicit cursor. (See the API in the java.util package)
/** Insert the given value just prior to the implicit cursor position. A subsequent
call to previous()
should return the inserted value, and a subsequent call to next() should be
unaffected.
*/public void add (E value);
Implement the add(E) method in your ArrayListIterator and RefListIterator classes.
Test your solution using DriverLabListIterator.
DriverLabEquals.java
package listDriver; import list.*;
/** * Data Structures and Algorithms. * *Compare lists for equality * * @author (sdb) * @version (2020) */ public class DriverLabEquals { static final int MAX = 1000000; public static void main() { System.out.println ("Testing the equals(Object) method for lists"); List
private static void init(List
private static void testEquals (List
DriverLabListIterator.java
package listDriver;
import list.*; /** * Test Iterators and ListIterators. * * @author (sdb) * @version (Sep 2020) */ public class DriverLabListIterator { public static void main(String [] args) { List
System.out.println ("Testing ListIterators for ArrayLists"); testListIterators (new ArrayList
private static void testIterators (List
System.out.println("Names in reverse order: "); itty = names.listIterator(names.size()); while (itty.hasPrevious()) System.out.print(itty.previous()+" "); // sue bill james joe harry mary james System.out.println(); }
LabDeleteListIterator.java
package listDriver; import list.*;
/** * Lab Problem. Method to search a list for the first pair of equal neighbors. * Delete the first member of that pair. * * @author (sdb and PUT YOUR NAME HERE!) * @version (2020) */ public class LabDeleteListIterator { static List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
