Help starting an assingment
this is my first post on these forums so bear with me if you can.
i have a java assignment that requires us to implement an arraylist class ourselves without importing from java.util.
for some reason my brain is not wrapping itself around this problem. i am going to copy and paste the assignment so it can be seen.
Your programming assignment is to implement an ArrayList class yourself (rather than using the class already in Java. That means DO NOT import java.util.ArrayList as that will confuse the compiler.)
You need not use any type parameter, so all elements of the ArrayList will be of type Object. You need to create a private array of type Object that will hold the elements; it could start out at length 10. If the user tries to add more elements than the array can hold, you need to create another array, and then copy the existing elements from the old array to the new one. The new array should be twice the size of the old one. You may need to repeat this process if the new array is exceeded.
Here is the interface you need to implement for ArrayList:
public ArrayList( ) // constructor that creates the private array
public void add(Object element) // add an element to the list
public Object get(int i) // return the element at index i
public int size( ) // return the number of elements in the list (which is NOT necessarily the length of your private array)
public void clear( ) // remove all elements from the list
public boolean isEmpty( ) // obvious
public String toString( ) // returns a String like [ firstElement, secondElement, … ] where you get the first element etc. by calling the to String method of each element in the list. Example [“Per”,”Tom”,”Kari”].
Also create a Main class that tests all functionality of your ArrayList implementation. It is best to do the complete Main class before you even start on the ArrayList class. When you start the ArrayList class, first make dummy methods so that the Main class can compile. Of course, all of your positive test should fail at first, and then they will succeed one by one as you fill in the bodies.
i am not looking for someone to complete this assignment for me as that would not be good for my learning. i am trying to figure out how to start this thing, most notably the add method. i don't know why my brain wont compute this assignment, but it will not do it and it is driving me crazy.
if someone would be able to push me in the right direction, i am hoping that will throw the lightswitch on in my head so i can stop feeling like an idiot.
Thanks in advance for any help.