Question: Create a file named StudentArrayList.java , within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It
Create a file named StudentArrayList.java, within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other words, the class StudentArrayList must implement the interface SimpleArrayList. You have to write the code for each of the functions specified in the SimpleArrayList interface. Make sure the class that implements SimpleArrayList is named "StudentArrayList" or else the test code will not compile.
All of the documentation for the function guidelines may be found in the interface. This assignment can be a lot of programming if you do not follow the DRY (Don't Repeat Yourself) programming principle. Though it may look like a lot of work, in reality, it is much less because many methods depend on each other. If you make sure you call other smaller methods in the larger methods you will save your self a lot of time.
You are not allowed to use any 3rd party data structures or libraries such as or anything in the Java.Utils package.
Submit the file named StudentArrayList.java to Grader Than for grading.
Hints:
- Make an object array (Object[]) as a field. Use the array to store elements added to the class. If an item is removed from the StudentArrayList all items to the right of the item that is removed must be shifted over one place to the left. When the array reaches capacity, you must augment the size of the object array by creating a larger empty array and copying elements from the old array into the new array.
- Use .equals() to test the equality of elements in the Object array.
- The size() function should return the total number of added items to the class not the total capacity of the internal array.
the interface of SimpleArrayList as followed by:
public interface SimpleArrayList{ /** * Returns the number of elements in this list. If this list contains more * than Integer.MAX_VALUE elements, returns * Integer.MAX_VALUE. * * @return the number of elements in this list */ int size(); /** * Returns true if this list contains no elements. * * @return true if this list contains no elements */ boolean isEmpty(); /** * Returns true if this list contains the specified element. More * formally, returns true if and only if this list contains at * least one element e * * @param o * element whose presence in this list is to be tested * @return true if this list contains the specified element */ boolean contains(E o); /** * Returns an array containing all of the elements in this list in proper * sequence (from first to last element). * * * The returned array will be "safe" in that no references to it are * maintained by this list. (In other words, this method must allocate a new * array even if this list is backed by an array). The caller is thus free * to modify the returned array. * *
* This method acts as bridge between array-based and student.SimpleArrayList-based * APIs. * * @return an array containing all of the elements in this list in proper * sequence */ E[] toArray(); /** * Appends the specified element to the end of this list * * @param e * element to be appended to this list */ void add(E e); /** * Removes the first occurrence of the specified element from this list, if * it is present (optional operation). If this list does not contain the * element, it is unchanged. * * @param o * element to be removed from this list, if present */ void remove(E o); /** * Returns true if this list contains all of the elements of the * specified student.SimpleArrayList. * * @param c * student.SimpleArrayList to be checked for containment in this list * @return true if this list contains all of the elements of the * specified student.SimpleArrayList */ boolean containsAll(SimpleArrayList
c); /** * Appends all of the elements in the specified student.SimpleArrayList to the end * of this list, in the order that they are returned by the specified * student.SimpleArrayList. * * @param c * student.SimpleArrayList containing elements to be added to this list * @return true if this list changed as a result of the call */ boolean addAll(SimpleArrayList c); /** * Inserts all of the elements in the specified student.SimpleArrayList into this * list at the specified position. Shifts the element currently at that * position (if any) and any subsequent elements to the right (increases * their indices). The new elements will appear in this list in the order * that they are returned by the specified student.SimpleArrayList's iterator. The * behavior of this operation is undefined if the specified student.SimpleArrayList * is modified while the operation is in progress. * * @param index * index at which to insert the first element from the specified * student.SimpleArrayList * @param c * student.SimpleArrayList containing elements to be added to this list * @return true if this list changed as a result of the call */ boolean addAll(int index, SimpleArrayList c); /** * Removes from this list all of its elements that are contained in the * specified student.SimpleArrayList. * * @param c * student.SimpleArrayList containing elements to be removed from this * list * @return true if this list changed as a result of the call */ boolean removeAll(SimpleArrayList c); /** * Retains only the elements in this list that are contained in the * specified student.SimpleArrayList. In other words, removes from this list all of * its elements that are not contained in the specified student.SimpleArrayList. * * @param c * student.SimpleArrayList containing elements to be retained in this * list * @return true if this list changed as a result of the call */ boolean retainAll(SimpleArrayList c); /** * Removes all of the elements from this list (optional operation). The list * will be empty after this call returns. * */ void clear(); /** * Compares the specified object with this list for equality. Returns * true if and only if the specified object is also a list, both * lists have the same size, and all corresponding pairs of elements in the * two lists are equal. In other words, two lists are defined to be * equal if they contain the same elements in the same order. This * definition ensures that the equals method works properly across different * implementations of the student.SimpleArrayList interface. * * @param o * the object to be compared for equality with this list * @return true if the specified object is equal to this list */ @Override boolean equals(Object o); /** * Returns the element at the specified position in this list. This should raise an IndexOutOfBoundsException * if there is no item at the specified index. * * @param index * index of the element to return * @return the element at the specified position in this list */ E get(int index); /** * Replaces the element at the specified position in this list with the * specified element (optional operation). * * @param index * index of the element to replace * @param element * element to be stored at the specified position * @return the element previously at the specified position */ void set(int index, E element); /** * Inserts the specified element at the specified position in this list * (optional operation). Shifts the element currently at that position (if * any) and any subsequent elements to the right (adds one to their * indices). * * @param index * index at which the specified element is to be inserted * @param element * element to be inserted */ void add(int index, E element); /** * Removes the element at the specified position in this list (optional * operation). Shifts any subsequent elements to the left (subtracts one * from their indices). Returns the element that was removed from the list. * * @param index * the index of the element to be removed * @return the element previously at the specified position */ void remove(int index); // Search Operations /** * Returns the index of the first occurrence of the specified element in * this list, or -1 if this list does not contain the element. * * @param o * element to search for * @return the index of the first occurrence of the specified element in * this list, or -1 if this list does not contain the element */ int indexOf(E o); /** * Returns the index of the last occurrence of the specified element in this * list, or -1 if this list does not contain the element. * * @param o * element to search for * @return the index of the last occurrence of the specified element in this * list, or -1 if this list does not contain the element */ int lastIndexOf(E o); /** * Returns a student.SimpleArrayList of the portion of this list between the * specified fromIndex, inclusive, and toIndex, exclusive. * (If fromIndex and toIndex are equal, the returned list * is empty.) * * * @param fromIndex * low endpoint (inclusive) of the subList * @param toIndex * high endpoint (exclusive) of the subList * @return a view of the specified range within this list */ SimpleArrayList subList(int fromIndex, int toIndex); /** * Returns a string of all the items within the list delineated with a * comma. So you can simply understand what is within this student.SimpleArrayList. * If nothing is in the list an empty string should be returned. * * @return A string indicating the items within the list. */ @Override String toString(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
