Question
Java Description The task is to write your own array list (growable array) that stores elements that are objects of a parent class or any
Java
Description
The task is to write your own array list (growable array) that stores elements that are objects of a parent class or any of its child classes but does not allow any other type of objects to be stored. You will create a general data class and two specific data classes that inherit from that class. You will then write the array list to hold any objects of the general data class. Finally, you will test your array list using JUnit tests to prove that it does what it should. Details Your array list must be named DataList. Start with an array with room for 10 elements. Keep all elements contiguous (no blank places) at the low end of the indices. When the array is full, grow it by doubling the size. (Do not use any built-in methods to copy the array elements. Write your own code to do this.) You do not have to shrink the array when elements are removed. The array list must have the following public methods (listed in UML style where GenClass is your general data class): insert(index: int, obj: GenClass) : boolean o Inserts the given object at the given index, moving all elements up one from that index forward to make room, growing the array if necessary. If the index is out of range, the method returns false. If the object is successfully inserted, it returns true. add(obj: GenClass): int o Adds the given object to the end of the list (the next available place in the array), gorwing the array if necessary, and returns the index where that object was added. set(index: int, obj: GenClass) : GenClass o Replaces the object in the list at the given index with this object. If the index is out of range, the method returns null. If the operation is successful, the method returns the object that was replaced by this one. delete(index: int) : GenClass o Deletes the object at the given index from the list, moving all elements above this index down to fill in the hole in the list. If the index is out of range, the method returns null. If the operation is successful, the method returns the object that was deleted. removeFirst(obj: GenClass) : boolean o Removes the first instance of this object from the list, moving all elements above this index down to fill in the hole in the list. If the object does not exist in the list, the method returns false. If the operation is successful, the method returns true. removeAll(obj: GenClass) : int o Removes all instances of this object from the list, moving elements above each down to fill in the hole in the list. Returns the number of objects removed. report(index: int) : GenClass o Reports the object in the list at the given index. If the index is out of range, returns null. findFirst(obj: GenClass) : int o Finds the first instance of the given object in the list and returns the index where it was found. Returns -1 if it is not found. findLast(obj: GenClass) : int o Finds the last instance of the given object in the list and returns the index where it was found. (Search from the end for efficiency.) Returns -1 if it is not found. size() : int o Reports the number of elements currently stored in the list. capacity() : int o Reports the current size of the underlying array. toString() : String o Reports a String representation of the list of objects currently stored in it, in the format [first obj String, second obj String, ..., last obj String] where each object is displayed using their toString method. You are welcome to add private methods to the DataList class if you think they would be helpful, but this is not required. You are not allowed to use a Java ArrayList in this project. The whole idea is to create your own. The JUnit tests need to test all possible outcomes of all the methods listed above for the general class. For example, the set method should be tested for when the list is empty, when the index is larger than the current size, when the index is less than zero, and when the index is good. The tests should confirm that the new value replaced the old in the list and that the old value was returned. The general data class should be named GenClass and represent some real type of object or concept and have at least two private fields, a default and a full constructor, getters, setters, an equals and hashCode method, and a toString() that displays the values of all fields. One of the fields should be some unque identifier that can be used for the equals method. The child classes should each add some unique field or fields that uniquely identify this type of object and distinguish it from any other type. They will need a new default constructor, a modified full constructor, and toString(), and getters and setters for the new fields
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