Question
1.Become familiar with the dynamic allocation of array storage
2.Become familiar with ArrayList
Description:
Create your myIntArrayList class that is functionally similar to the formal Java ArrayList class.
Requirements:
Your myIntArrayList should contain the following methods and characteristics:
*Should contain a default constructor myIntArrayList()
*Should contain an alternative constructor myIntArrayList(int[] anArray) that allows the user to create an initial myIntArrayList that is equivalent to an array that is passed to the constructor
◦Should contain an alternative constructor myIntArrayList(myIntArrayList anExample) that will create an intMyArrayList identical to one that is passed to it
◦Should contain an void add(int index, int value) method
◾Need to check for appropriate index. If index is outside of the array boundaries, then add at the beginning or the end
◦Should contain a int remove(int index) method
◾If the index is outside of the array boundaries, then remove the first or last element
◦ Should contain a myIntArrayList simpleSort() method that will return another myIntArrayList object with the contents of the current object sorted using an insertion sort.
◦Should contain a int get(int index) method
◾If index is out of boundary then return either the first or last element
◦Should contain an int indexOf(int value) method
◾Returns the index of the first occurance of value
◦ Should contain an boolean isEmpty() method
◦Should contain a int size() method
◦ Should contain a void clear() method that empties the myIntArryList
◦ Should contain a void print() method that prints all elements of the myIntArrayList in one row delimited by one space
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
public class myIntArrayList {public int[] array;
public myIntArrayList()
{
array = new int[0];
}
public myIntArrayList(int[] anArray)
{
array = new int[anArray.length];
for(int i = 0; i < anArray.length; i++)
array[i] = anArray[i];...