Question: We have studied how an ArrayList is implemented by creating an underlying array (e.g., []) and storing the data in that array. The set,
![array (e.g., []) and storing the data in that array. The set,](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/01/65ba2604b1842_24465ba2604777b5.jpg)
We have studied how an ArrayList is implemented by creating an underlying array (e.g., []) and storing the data in that array. The set, get, add, remove, etc. methods were implemented by manipulating the data in the underlying array. Note that the ArrayList is a generic class. The type of data stored in the array can be any kind of Object. The type-parameter E is a placeholder for the actual type of data placed in the data structure (e.g., String, or Car, or Student). For this assignment, you must complete the given LucasArrayList class so that it implements the ListIterator interface that is defined in the java.util package in the Java lilbraries. You will need to complete the code of the given CurrentPosition class that is inside the LucasArrayList class. The purpose of this class is to be a kind of "bookmark" into the list. This "bookmark" object will need to remember where it currently is located inside the list, and to update that information appropriately every time the user moves the bookmark to the right (the .next() method) or to the left (the previous() method) in the list. You will need to define several instance fields for the CurrentPosition class, and to develop all the methods specified in the ListIterator interface. The "shell" or "stub" of the CurrentPosition class is provided to you, as shown below: private class CurrentPosition implements ListIterator ( } // you must write all of the code to implement this class This code will show a compiler error, since this class must contain all the methods specified in the ListIterator, and the given code does not. To fix this error you can hover your mouse over CurrentPosition and select "Add unimplemented methods" to have a stub of each of the required methods inserted. This is one example of how we like using a powerful IDE, instead of having to type everything ourself. You must implement the code for each method in CurrentPosition directly yourself, without using inheritance to "reach in" and use code already available in the Java libraries. The code is fairly simple, but you do need to do a couple of things. You can consult the Java API to see the functionality of a ListIterator . You should be sure to do appropriate error-checking in your CurrentPosition. For example, the next() method should throw a NoSuchElementException if the user attempts to move past the right end of the list. Also, the ListIterator must have moved either left or right at least once before altering an element in the List using set(). Therefore the set() method should throw an IllegalStateException if this is not the case. Similarly for the remove() method. You are given the Prog02_Tester class. If you have completed the methods in the CurrentPosition class correctly, then the main method in Prog02_Tester should execute without any errors. Your code must work for the given Tester. You can add extra code to the Tester, if you wish, to do more through error checking, but you must not alter the given Tester code in any way. To submit your work, upload a zipfile containing your LucasArrayList.java file to the Program 2 Assignment drop box in UNM Learn. Yes, you only need to submit one file, but you must still "zip up" that file and submit the zipfile. You should be sure to include YOUR NAME in a comment at the top of your source code file. Your source code must use proper style, i.e., variables should be well named (name is not too short, not too long, and is meaningful), and bodies of loops, if's, etc. should be properly indented.
Step by Step Solution
There are 3 Steps involved in it
It seems like you need to implement a CurrentPosition class that implements the ListIterator interfa... View full answer
Get step-by-step solutions from verified subject matter experts
