public class ListProgram3 implements ListInterface{ private static final int MAX_INITIAL_LIST = 10; private Object[] items; // array of list items private int numItems; // number of items in the list // numItems <= size of array public ListProgram3(){ items = new Object[MAX_INITIAL_LIST]; numItems = 0; } public boolean isEmpty(){ return (numItems == 0); } public int size(){ return numItems; } public void removeAll(){ numItems = 0; items = new Object[MAX_INITIAL_LIST]; } public void add (int index, Object item) throws ListIndexOutOfBoundsException{ if(index<0 || index>numItems){ throw new ListIndexOutOfBoundsException ("List index is out of bounds in method add"); } else{ if(numItems == items.length){ //resize Object[] newArray = new Object[2*items.length]; for(int a=0; a< items.length;a++){ newArray[a]=items[a]; } items=newArray; } // end if // shift down for (int pos = numItems-1; pos>=index; pos--){ items[pos+1] = items[pos]; items[index] = item; numItems++; } // end for } // end else } // end add public void remove (int index) throws ListIndexOutOfBoundsException{ if(index<0 || index >numItems){ throw new ListIndexOutOfBoundsException ("List index is out of bounds in method remove"); } else{ for (int pos = index; pos <= numItems-2; pos++) items[pos] = items[pos+1]; numItems--; } // end else } //end remove public Object get (int index) throws ListIndexOutOfBoundsException{ if(index<0 || index>numItems){ throw new ListIndexOutOfBoundsException ("List index is out of bounds in method get"); } else return items[index]; } // end get } // end ListProgram3