Here is my interface:
public interface BasicList<E> { public void add(E element); public E get(int index); public void add(int index, E element); public void clear(); public boolean contains(E element); public int indexOf(E element); public E remove(E element); public E set(int index, E element); public int size(); }
Here is my class that implements it, right now I am only working on add() and get()
public class BasicArrayList<E> implements BasicList<E>
{ private int size; private Object[] array; public static final int DEFAULT_CAPACITY = 10; public BasicArrayList() { size = 0; array = new Object[DEFAULT_CAPACITY]; } public BasicArrayList(int capacity) { size = 0; array = new Object[capacity]; } public void add(E element) { array[0] = element; } public E get(int index) { return array[index]; } }
My problem I know is that I am trying to return an element and giving it an Object. However, I don't know how I would implement a get that would snatch an element out of an array. Thanks in advance!!