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;

}

Recommended Answers

All 7 Replies

Try dropping the word interface on line 10. If you are specifying implements it understand you are going to reference an interface.

Did that still got issues I cant seem to work out

Here are my errors now and my code. I really apreciate the help.
Here is new revised code:

package javafoundations;

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Iterator;
//--------------------------------------------------------------------------
//
//                     An interface for array lists.
//
//--------------------------------------------------------------------------

public class IndexList<T>
{

//--------------------------------------------------------------------------
//
//          Returns the number of elements in this list.
//
//--------------------------------------------------------------------------

  public int size()
  {
      return size();
  }

  //------------------------------------------------------------------------
  //
  //                Returns whether the list is empty.
  //
  //------------------------------------------------------------------------
  public boolean isEmpty()
  {
      return isEmpty;
  }
  //------------------------------------------------------------------------
  //
  // Inserts an element to be at index, shifting all elements after this.
  //
  //------------------------------------------------------------------------

  public void add(int index, int element) throws IndexOutOfBoundsException
  {

  }
  //------------------------------------------------------------------------
  //
  //         Returns the element at index, without removing it.
  //
  //------------------------------------------------------------------------

  public T get(int index) throws IndexOutOfBoundsException
  {
      return index;
  }
  //-----------------------------------------------------------------------
  //
  //      Removes and returns the element at index, shifting the element
  //      after this.
  //
  //-----------------------------------------------------------------------

  public T remove(int index) throws IndexOutOfBoundsException
  {
      return index;
  }
  //-----------------------------------------------------------------------
  //     Replaces the element at index with element, returning the previous
  //     element at index.
  //
  //-----------------------------------------------------------------------

  public T set(int index, T element) throws IndexOutOfBoundsException
  {
      return element;
  }

  //returns string representation of the bag
  public String toString()
  {
    return (index + element);
  }
}
package javafoundations;

import java.util.*;
import java.lang.*;
import java.io.*;
import javafoundations.*;


//--------------------------------------------------------------------------
//
//     Realization of an indexed list by means of an array, which is doubled
//  when the size of the indexed list exceeds the capacity of the array.
//
//--------------------------------------------------------------------------

public class ArrayIndexedList<T> implements IndexList<T>
{

  private T[] array;          // array storing the elements of the indexed list
  private int capacity = 16;  // initial length of array array
  private int size = 0;       // number of elements stored in the indexed list

  //-------------------------------------------------------------------------
  //
  //     Creates the indexed list with initial capacity 16.
  //
  //-------------------------------------------------------------------------

  public ArrayIndexedList()
  {
    array = (T[]) 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 T get(int range)throws IndexOutOfBoundsException
  {
    checkIndex(range, size());
    return array[range];
  }

//---------------------------------------------------------------------------
//
//         Replaces the element stored at the given index.
//
//---------------------------------------------------------------------------

  public T set(int range, T element) throws IndexOutOfBoundsException
  {
    checkIndex(range, size());
    T temp = array[range];
    array[range] = element;
    return temp;
  }

//---------------------------------------------------------------------------
//
//              Inserts an element at the given index.
//
//---------------------------------------------------------------------------

  public void add(int range, T element) throws IndexOutOfBoundsException
  {
    checkIndex(range, size() + 1);
    if (size == capacity)
    {                                   // an overflow
      capacity *= 2;
      T[] B =(T[]) new Object[capacity];
      for (int index=0; index<size; index++)
         B[index] = array[index];
         array = B;
    }

    for (int index=size-1; index>=range; index--)   // shift elements up
       array[index+1] = array[index];
       array[range] = element;
       size++;
  }

//---------------------------------------------------------------------------
//
//                Removes the element stored at the given index.
//
//---------------------------------------------------------------------------

  public T remove(int range) throws IndexOutOfBoundsException
  {
    checkIndex(range, size());
    T temp = array[range];
    for (int index=range; index<size-1; index++) // shift elements down
      array[index] = array[index+1];
    size--;
    return temp;
  }

//---------------------------------------------------------------------------
//
//       Checks whether the given index is in the range [0, n - 1]
//
//---------------------------------------------------------------------------

  protected void checkIndex(int range, int num) throws IndexOutOfBoundsException
  {
    if (range < 0 || range >= num) throw
            new IndexOutOfBoundsException("Illegal index: " + range);
  }
}

Here are the errors from the ArrayIndexedList class:

C:\Users\Linda\Documents\ArrayIndexedList.java:16: cannot find symbol
symbol: class IndexList
public class ArrayIndexedList<T> implements IndexList<T>
                                            ^
C:\Users\Linda\Documents\ArrayIndexedList.java:16: interface expected here
public class ArrayIndexedList<T> implements IndexList<T>
                                                     ^
C:\Users\Linda\Documents\ArrayIndexedList.java:31: warning: [unchecked] unchecked cast
found   : java.lang.Object[]
required: T[]
    array = (T[]) new Object[capacity]; // the compiler may warn, but this is ok
                  ^
C:\Users\Linda\Documents\ArrayIndexedList.java:94: warning: [unchecked] unchecked cast
found   : java.lang.Object[]
required: T[]
      T[] B =(T[]) new Object[capacity];
                   ^
2 errors
2 warnings

Tool completed with exit code 1

Now the errors for the IndexedList Class:

C:\Users\Linda\Documents\IndexList.java:35: cannot find symbol
symbol  : variable isEmpty
location: class javafoundations.IndexList<T>
      return isEmpty;
             ^
C:\Users\Linda\Documents\IndexList.java:55: incompatible types
found   : int
required: T
      return index;
             ^
C:\Users\Linda\Documents\IndexList.java:66: incompatible types
found   : int
required: T
      return index;
             ^
C:\Users\Linda\Documents\IndexList.java:82: cannot find symbol
symbol  : variable index
location: class javafoundations.IndexList<T>
    return (index + element);
            ^
C:\Users\Linda\Documents\IndexList.java:82: cannot find symbol
symbol  : variable element
location: class javafoundations.IndexList<T>
    return (index + element);
                    ^
5 errors

Tool completed with exit code 1

Some of these are simple errors I will get worked out but I am completely lost. I have reviewed and reviewed and still am having soooo many issues.

By the way thanks sooooo much! I am loosing my manors along with my mind! Sorry!

Judging by the comment at the top of IndexList you want it to be an interface, so define it as so. Interfaces do not allow for method bodies, just their signatures; the implementing classes will take care of that.

After making that an interface, and creating the other class (ArrayIndexedList) I don't get the errors you mentioned for it.

I am not sure how to make it an interface besides where I name my class. I will do some research on it. Hopefully I can get this one done. If not it will not hurt me much, to turn it in with errors. At least I get a grade. I need to get the other program for the flight repaired and turned in by 7pm tomorrow. That is a program that helps calculate 80% of my grade.

public interface MyInterface
{
   public void methodOne();
   public void methodTwo();
}

public class MyClass implements MyInterface
{
   public void methodOne()
   {
       //stuff goes here
   }

   public void methodTwo()
   {
       //stuff goes here
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.