I am having a problem getting this program to run. I have tried all I can but it keeps telling me It can not find the IndexList and it is here. You see it. Maybe part of the code is missing something I am not sure. Help Please Due in 2 days and have 2 more programs to write.
package net.datastructures;
//--------------------------------------------------------------------------
//
// Program for an indexed list by an array, which is doubled
// when the size of the indexed list exceeds the capacity of the array.
//
//--------------------------------------------------------------------------
public class ArrayIndexList<E> implements interface IndexList<E>
{
private E[] A; // array storing the elements of the indexed list
private int capacity = 16; // initial length of array A
private int size = 0; // number of elements stored in the indexed list
//-------------------------------------------------------------------------
//
// Creates the indexed list with initial capacity 16.
//
//-------------------------------------------------------------------------
public ArrayIndexList()
{
A = (E[]) new Object[capacity]; // the compiler may warn, but this is ok
}
//---------------------------------------------------------------------------
//
// Returns the number of elements in the indexed list.
//
//---------------------------------------------------------------------------
public int size()
{
return size;
}
//---------------------------------------------------------------------------
//
// Returns whether the indexed list is empty.
//
//---------------------------------------------------------------------------
public boolean isEmpty()
{
return size() == 0;
}
//---------------------------------------------------------------------------
//
// Returns the element stored at the given index.
//
//---------------------------------------------------------------------------
public E get(int r)throws IndexOutOfBoundsException
{
checkIndex(r, size());
return A[r];
}
//---------------------------------------------------------------------------
//
// Replaces the element stored at the given index.
//
//---------------------------------------------------------------------------
public E set(int r, E e) throws IndexOutOfBoundsException
{
checkIndex(r, size());
E temp = A[r];
A[r] = e;
return temp;
}
//---------------------------------------------------------------------------
//
// Inserts an element at the given index.
//
//---------------------------------------------------------------------------
public void add(int r, E e) throws IndexOutOfBoundsException
{
checkIndex(r, size() + 1);
if (size == capacity)
{ // an overflow
capacity *= 2;
E[] B =(E[]) new Object[capacity];
for (int i=0; i<size; i++)
B[i] = A[i];
A = B;
}
for (int i=size-1; i>=r; i--) // shift elements up
A[i+1] = A[i];
A[r] = e;
size++;
}
//---------------------------------------------------------------------------
//
// Removes the element stored at the given index.
//
//---------------------------------------------------------------------------
public E remove(int r) throws IndexOutOfBoundsException
{
checkIndex(r, size());
E temp = A[r];
for (int i=r; i<size-1; i++) // shift elements down
A[i] = A[i+1];
size--;
return temp;
}
//---------------------------------------------------------------------------
//
// Checks whether the given index is in the range [0, n - 1]
//
//---------------------------------------------------------------------------
protected void checkIndex(int r, int n) throws IndexOutOfBoundsException
{
if (r < 0 || r >= n) throw new IndexOutOfBoundsException("Illegal index: " + r);
}
}
package net.datastructures;
import java.util.Iterator;
//--------------------------------------------------------------------------
//
// An interface for array lists.
//
//--------------------------------------------------------------------------
public interface IndexList<E>
{
//--------------------------------------------------------------------------
//
// Returns the number of elements in this list.
//
//--------------------------------------------------------------------------
public int size();
//------------------------------------------------------------------------
//
// Returns whether the list is empty.
//
//------------------------------------------------------------------------
public boolean isEmpty();
//------------------------------------------------------------------------
//
// Inserts an element e to be at index i, shifting all elements after this.
//
//------------------------------------------------------------------------
public void add(int i, E e) throws IndexOutOfBoundsException;
//------------------------------------------------------------------------
//
// Returns the element at index i, without removing it.
//
//------------------------------------------------------------------------
public E get(int i) throws IndexOutOfBoundsException;
//-----------------------------------------------------------------------
//
// Removes and returns the element at index i, shifting the element
// after this.
//
//-----------------------------------------------------------------------
public E remove(int i) throws IndexOutOfBoundsException;
//-----------------------------------------------------------------------
// Replaces the element at index i with e, returning the previous
// element at i.
//
//-----------------------------------------------------------------------
public E set(int i, E e) throws IndexOutOfBoundsException;
}