Avatar of yunji1
yunji1
 asked on

ArrayList Interface Java Collections Error

I cannot figure out why this doesn't work. I need to implement the Java ArrayList Collections into my existing program methods. I keep getting a wierd compile error and it doesn't run. The teacher states that I don't need to handle exceptions.

Here is the error:
Note: C:\NEU\JAVA\HW8\test\MyArrayList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Tool completed successfully

The
////////MyArrayList.java///////////////////
import java.util.*;
 
class MyArrayList implements MyList
{
     private ArrayList data;
     final int NOT_FOUND = -1;
     private int incIndex = 0;
 
     public void clear()
     {
         data.clear();
     }
 
     //Returns the current number of elements in the list.
     public int size()
     {
          return data.size();
     }
 
     //Returns true if no elements, false otherwise.
     public boolean isEmpty()
     {
          return data.isEmpty();
     }
 
     //Returns true if this list contains the specified element,
     //false otherwise.
     public boolean contains(Object obj)
     {
          return data.contains(obj);
     }
 
     //Adds element to end of list. Increases size() by 1.
     //Only need to return true, since this assignment requires that this
     //operation always succeeds.
     public boolean add(Object obj)
     {
          return data.add(obj);
     }
 
     //Removes first occurrence of element if present.
     //Returns true if collection modified (size decreases by one),
     //false otherwise.
     public boolean remove(Object obj)
     {
         incIndex = data.indexOf(obj);
		 if(incIndex != NOT_FOUND)
		 {
		      data.remove(incIndex);
              return true;
		 }
		 else
		 {
		      return false;
         }
     }
 
     //Returns a MyIterator object, default initialized to refer to the
     //first element.
     /*public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;
 
 
          public MyArrayListIterator(List myList)
          {
               AL = myList.listIterator();
          }
 
          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
               return(cursor<AL.size());
          }
 
          //Returns the next element in the list.
          public Object next()
          {
               return AL.get(cursor++);
          }
 
          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               AL.remove(AL.get(cursor));
          }
     }*/
 
     //Returns the element at index, null if not present or
     //index is out of range.
     public Object get(int index)
     {
          if(index >= 0 && index < data.size())
          {
               return data.get(new Integer(index));
          }
          else
          {
               return null;
          }
     }
 
     //Replaces the element at the specified index in this list
     //with the specified element.
     //Returns the original element at index, null if not present
     //or index in out of range.
     public Object set(int index, Object obj)
     {
          return data.set(index,obj);
     }
 
     //Returns the index in this list of the first occurrence of the
     //specified element, or -1 if this list does not contain this element.
     public int indexOf(Object obj)
     {
         return data.indexOf(obj);
     }
}
//////MyList.java///////////////////
interface MyList
{
	 //Removes all of the elements from this list.
	 //Deallocates all existing dynamically allocated memory.
	 //size() goes to zero.
	 public void clear();
 
	 //Returns the current number of elements in the list.
	 public int size();
 
	 //Returns true if no elements, false otherwise.
	 public boolean isEmpty();
 
	 //Returns true if this list contains the specified element,
	 //false otherwise.
	 public boolean contains(Object o);
 
	 //Adds element to end of list. Increases size() by 1.
	 //Only need to return true, since this assignment requires that this
	 //operation always succeeds.
	 public boolean add(Object o);
 
	 //Removes first occurrence of element if present.
	 //Returns true if collection modified (size decreases by one),
	 //false otherwise.
	 public boolean remove(Object o);
 
	 //Returns a MyIterator object, default initialized to refer to the
	 //first element.
	 //public MyIterator iterator();
 
	 //Returns the element at index, null if not present or
	 //index is out of range.
	 public Object get(int index);
 
	 //Replaces the element at the specified index in this list
	 //with the specified element.
	 //Returns the original element at index, null if not present
	 //or index in out of range.
	 public Object set(int index, Object o);
 
 
	 //Returns the index in this list of the first occurrence of the
	 //specified element, or -1 if this list does not contain this element.
	 public int indexOf(Object o);
 
 
}
 
///////////////TestMyList2.java/////////////////////
import java.io.*;
 
class TestMyList2 {
    public static void main(String args[])
    {
        System.out.println("----------- ARRAY TEST --------------");
	MyList alist = new MyArrayList();
	testList(alist);
    /*    System.out.println("----------- LINK LIST TEST --------------");
	MyList llist = new MyLinkList();
	testList(llist);*/
    }
 
    static void testList(MyList ml)
    {
	PrintStream o = System.out;
 
	if(ml.size() != 0 || !ml.isEmpty())
	    o.println("Logic error " + 1);
	ml.clear();
        if(ml.size() != 0 || !ml.isEmpty())
	    o.println("Logic error " + 2);
	if(ml.contains(new Double(3.4)))
	    o.println("Logic error " + 3);
	for(int i = 0; i < 1000; i++)
	    ml.add(new Integer(i));
	if(ml.size() != 1000 || ml.isEmpty())
            o.println("Logic error " + 4);
        ml.clear();
        if(ml.size() != 0 || !ml.isEmpty())
            o.println("Logic error " + 5);
	for(int i = 0; i < 2000; i++)
	    ml.add(new Integer(i));
	for(int i = 0; i < 2000; i++) {
	    if(!ml.contains(new Integer(i)))
                o.println("Logic error " + 6);
	}
        if(!ml.remove(new Integer(0)))
            o.println("Logic error " + 7);
	if(ml.size() != 1999)
            o.println("Logic error " + 8);
        if(!ml.remove(new Integer(1999)))
            o.println("Logic error " + 9);
	if(ml.size() != 1998)
            o.println("Logic error " + 10);
	ml.clear();
	ml.add(new Integer(3));
	ml.add(new Double(3.4));
	ml.add(new Short((short)9));
        if(ml.size() != 3)
            o.println("Logic error " + 11);
        Double d1 = (Double)ml.get(1);
	if(d1 == null || !d1.equals(new Double(3.4)))
            o.println("Logic error " + 12);
        d1 = (Double)ml.set(1,new Long(234));
        Long l1 = (Long)ml.get(1);
	if(d1 == null || l1 == null ||
		!d1.equals(new Double(3.4)) || !l1.equals(new Long(234)))
            o.println("Logic error " + 13);
	if(ml.indexOf(new String("not present")) != -1)
            o.println("Logic error " + 14);
	if(ml.indexOf(new Short((short)9)) != 2)
            o.println("Logic error " + 15);
	o.println("Test MyIterator:");
	/*MyIterator it = ml.iterator();
	for(int i = 0; it.hasNext(); i++)
	    o.println(i + " " + it.next());
	it = ml.iterator();
        if(ml.size() != 3 || !it.hasNext())
            o.println("Logic error " + 16);
        it.next();    // new call, added for this assignment
        it.remove();
        if(ml.size() != 2 || !it.hasNext())
            o.println("Logic error " + 17);
        it.next();  // advance to next (last)
        it.remove();
        // next statement changed for this assignment. was
        // it.hasNext() for previous assignment
        if(ml.size() != 1 || !it.hasNext())
            o.println("Logic error " + 18);*/
 
    }
}

Open in new window

Java

Avatar of undefined
Last Comment
yunji1

8/22/2022 - Mon
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
But when I run the program it spits out garble that doesn't mean anything. Here is what it spits out.

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
                  show splash screen with specified image
Press any key to continue . . .
yunji1

ASKER
I know what I did wrong in the beginning I didn't fully initialize the ArrayList variable.

private ArrayList data = new ArrayList();

My next question is on the MyIterator implementation: I am missing something here and I can't quite figure it out.

public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;


          public MyArrayListIterator(List myList)
          {
               AL = myList.listIterator();
          }

          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
               return AL.hasNext();
          }

          //Returns the next element in the list.
          public Object next()
          {
               return AL.next()l
          }

          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               AL.remove();
          }
     }
yunji1

ASKER
This is the error message when I try and compile:
C:\NEU\JAVA\HW8\test\MyArrayList.java:63: cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
location: class MyArrayList.MyArrayListIterator
          return new MyArrayListIterator(this);
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
CEHJ

>>But when I run the program it spits out garble

How are you trying to run it? The program compiles
yunji1

ASKER
Disregard that last comment about garble. I got it to work because I wasn't initializing the ArrayList object.

private ArrayList data = new ArrayList();
////////////////////This part works now......

My next question is on the MyIterator implementation: I am missing something here and I can't quite figure it out.
public MyIterator iterator()

This is the error message when I try and compile with the MyIterator section uncommented and included:

C:\NEU\JAVA\HW8\test\MyArrayList.java:63: cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
location: class MyArrayList.MyArrayListIterator
          return new MyArrayListIterator(this);
/////////////////////////////////////////////////
Can you tell me what is wrong with my logic:
public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;


          public MyArrayListIterator(List myList)
          {
               AL = myList.listIterator();
          }

          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
               return AL.hasNext();
          }

          //Returns the next element in the list.
          public Object next()
          {
               return AL.next()l
          }

          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               AL.remove();
          }
     }
CEHJ

>>
cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
>>

You need that constructor declared in the iterator class to be able to call it
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
I don't understand?

Where do I call MyArraListIterator(MyArrayList)??????????

public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;

          public MyArrayListIterator(ListIterator ml)
          {
               AL = ml.listIterator();
          }

          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
               return AL.hasNext();
          }

          //Returns the next element in the list.
          public Object next()
          {
               return AL.next();
          }

          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               AL.remove();
          }
     }
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
I changed the code and it is giving me an error:

.\MyArrayList.java:72: cannot find symbol
symbol  : method listIterator()
location: interface MyList
               AL = myList.listIterator();
                                  ^
I don't understand why this doesn't work.
Thank you for all your help.
public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;
 
          public MyArrayListIterator(MyList myList)
          {
               AL = myList.listIterator();
          }

Open in new window

yunji1

ASKER
I thought that I needed to have the variable type ListIterator?

putblic MyArrayListIterator(ListIterator myList)

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
CEHJ

Well of course now that's fixed, you have further errors. You need to be able to read the very precise information the compiler is giving you:

>>
.\MyArrayList.java:72: cannot find symbol
symbol  : method listIterator()
>>

The above means that the method you're calling doesn't exist. You probably need to be calling that on the underlying *actual* List, not your custom class. Please post your corrected code to date as separate file attachments
yunji1

ASKER
I've looked at it about 6 hours yesterday and about 2 hours today and still don't understand it.

The example that was given was:

class list1 {
     public static void man(String args[]) {
           ArrayList  al = new ArrayList();
           testList(al);

     static void testList(List list) {
          ListIterator iter = list.listIterator();
          while(iter.hasNext()) {
                   Object 0 = iter.next();
...............................................................................................
This example was give so that we can incorporate it into our program. I have done this from what it looks like and still am unsuccessful in getting it to work. As I do not understand what  or why it doesn't work. It continues to crash. I understand what you are saying by looking at the error message and determining what the error is, but I don't understand it.

\MyArrayList.java:64: cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
location: class MyArrayList.MyArrayListIterator
              return new MyArrayListIterator(this);
             ^

import java.util.*;
 
class MyArrayList implements MyList
{
     private ArrayList data = new ArrayList();
     final int NOT_FOUND = -1;
     private int incIndex = 0;
 
     public void clear()
     {
         data.clear();
     }
 
     //Returns the current number of elements in the list.
     public int size()
     {
          return data.size();
     }
 
     //Returns true if no elements, false otherwise.
     public boolean isEmpty()
     {
          return data.isEmpty();
     }
 
     //Returns true if this list contains the specified element,
     //false otherwise.
     public boolean contains(Object obj)
     {
          return data.contains(obj);
     }
 
     //Adds element to end of list. Increases size() by 1.
     //Only need to return true, since this assignment requires that this
     //operation always succeeds.
     public boolean add(Object obj)
     {
          return data.add(obj);
     }
 
     //Removes first occurrence of element if present.
     //Returns true if collection modified (size decreases by one),
     //false otherwise.
     public boolean remove(Object obj)
     {
         incIndex = data.indexOf(obj);
         if(incIndex != NOT_FOUND)
         {
	 data.remove(incIndex);
            return true;
         }
         else
         {
             return false;
         }
     }
 
     //Returns a MyIterator object, default initialized to refer to the
     //first element.
 
     public MyIterator iterator()
     {
          return new MyArrayListIterator(this);
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator iter;
          private boolean pending;
 
          public MyArrayListIterator(List l)
          {
               iter = l.listIterator();
          }
 
          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
              pending = true;
        	   while (iter.hasNext())
        	   {
	       return true;
	   }
	   return false;
          }
 
          //Returns the next element in the list.
          public Object next()
          {
                if (!pending) hasNext();
	    pending = false;
                return iter.next();
          }
 
          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               iter.remove();
          }
     }
 
 
     //Returns the element at index, null if not present or
     //index is out of range.
     public Object get(int index)
     {
          if(index >= 0 && index < data.size())
          {
               return data.get(new Integer(index));
          }
          else
          {
               return null;
          }
     }
 
     //Replaces the element at the specified index in this list
     //with the specified element.
     //Returns the original element at index, null if not present
     //or index in out of range.
     public Object set(int index, Object obj)
     {
          return data.set(index,obj);
     }
 
     //Returns the index in this list of the first occurrence of the
     //specified element, or -1 if this list does not contain this element.
     public int indexOf(Object obj)
     {
         return data.indexOf(obj);
     }
}

Open in new window

CEHJ

>>Please post your corrected code to date as separate file attachments

>>
I understand what you are saying by looking at the error message and determining what the error is, but I don't understand it.

\MyArrayList.java:64: cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
location: class MyArrayList.MyArrayListIterator
              return new MyArrayListIterator(this);
             ^
>>

We'd got beyond that problem yesterday (see below). Look carefully at the comments above about this issue

>>
I changed the code and it is giving me an error:

.\MyArrayList.java:72: cannot find symbol
symbol  : method listIterator()
location: interface MyList
               AL = myList.listIterator();
>>
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
"The above means that the method you're calling doesn't exist. You probably need to be calling that on the underlying *actual* List, not your custom class."
------What does this mean?

You told me to pass (MyList list) to the constructor. public MyArrayListIterator(MyList myList)

If I define an object .......ListIterator AL......... then I want to assign it
AL = myList.listIterator();..................this isn't working. It cannot find listIterator() as a function.
yunji1

ASKER
Up to date code with the changes you suggested. When I compile it cannot find the listIterator.

The example given to me by the class stated:
static void testList(List list) {
          ListIterator iter = list.listIterator();
          while(iter.hasNext()) {
                   Object 0 = iter.next();


So does the data type need to be List or MyList...........either way it doesn't compile.

public MyIterator iterator()
{
    return new MyArrayListIterator(this);
}
private class MyArrayListIterator implements MyIterator
{
      private ListIterator AL;
      private boolean pending;
 
      public MyArrayListIterator(MyList myList)
      {
           AL = myList.listIterator();
      }

Open in new window

CEHJ

You still haven't posted your files as i requested ...
Your help has saved me hundreds of hours of internet surfing.
fblack61
yunji1

ASKER
Here are all the programs up to date.
Allprograms.txt
CEHJ

OK - your current error is ...?
yunji1

ASKER
oh my gosh.....................................*sigh*

MyArrayList.java:72: cannot find symbol
symbol  : method listIterator()
location: interface MyList
               AL = myList.listIterator();


âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

That's for a  similar reason as before - you're calling a method that doesn't exist
yunji1

ASKER
This is the part I don't understand. When the instructor executed his code he stated that listIterator() was a built in Java function part of the List Collections. Is this wrong?


Im begging at this point due to frustration, can you just tell me what / how to fix this looking at the code that I submitted to you. PLEASE.
CEHJ

>>was a built in Java function part of the List Collections. Is this wrong?

No it isn't wrong. But that's not what you've got - you've got a type of MyList (as the error message tells you)

>>Im begging at this point due to frustration ...

It's not going to help you in the longer term if i just do it all for you is it? I'm trying to show you that the *compiler's* trying to show you .. what's wrong
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
yunji1

ASKER
spending HOURS upon HOURS is a helpful learning tool? I don't want or intend to become a Java expert. I just want to get through it OK?


>>"you've got a type of MyList (as the error message tells you)"

You advised me to use this and it still didn't work. Now I am asking what you advise now?
CEHJ

>>You advised me to use this and it still didn't work

Sorry - i'm not with you - to use what? That line has been in your code from the outset...
yunji1

ASKER
Original Code: public MyArrayListIterator(List myList)

Original Error Message:
This is the error message when I try and compile:
C:\NEU\JAVA\HW8\test\MyArrayList.java:63: cannot find symbol
symbol  : constructor MyArrayListIterator(MyArrayList)
location: class MyArrayList.MyArrayListIterator
          return new MyArrayListIterator(this);
///////////////////////////////////////////////////////////////////////////////////////////
>>As i said, you need the following ctor in your class:1:
>>public MyArrayListIterator(MyList myList)
////////////////////////////////////////////////////////////////////////////////////////////

Current Error Message:

MyArrayList.java:72: cannot find symbol
symbol  : method listIterator()
location: interface MyList
               AL = myList.listIterator();

The code is almost complete. Can you tell me what I need to implement or write to do to fix it?
At this point I don't know if you are truely trying to help or your toying with me?????????????
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
My attitude? My attitude is slowly changing over the course of this thread and is the direct reflection of one pointing at the moon, but the spectator doesn't know where or what a moon is.

>>your latest error message, it's telling you what's wrong and i've amplified that if you look above.

How do I access built in Java iterator Collection functions (hasNext, next & remove) with my current code and implentation? With my current code I am unable to access these iterator functions.
CEHJ

You need to give MyList a method that returns the Iterator you want. At the moment you're calling a method that doesn't exist. Then, you need to *actually* call a method that return an Iterator on the underlying List in the class that implements MyList
yunji1

ASKER
>>You need to give MyList a method that returns the Iterator you want.
You want me to modify MyList.java by adding another method?

>>At the moment you're calling a method that doesn't exist.
I'm trying to call the Java Builit in List Collections. How can I do this?

>>Then, you need to *actually* call a method that return an Iterator on the underlying List in the class that implements MyList
I don't even know what this means.

I tried to research this again by getting examples on the internet but each time comes up with a failure. I think I may just turn in the assignment as is and get whatever grade is given because I can't stand to stomach looking at it any further and I am tired ot asking questions with no solutions.

Is this what people pay for on this sight? In some ways I feel I have been let down. Do you have this question in your Queue or can others view it as well.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
CEHJ

>>You want me to modify MyList.java by adding another method?

You need to if you want to call it
yunji1

ASKER
Error Message: I cannot figure out why it crashes to a NullPointer when it calls the:
public MyIterator iterator()

----------- ARRAY TEST --------------
Test MyIterator:
Exception in thread "main" java.lang.NullPointerException
        at MyArrayList$MyArrayListIterator.hasNext(MyArrayList.java:78)
        at TestMyList2.testList(TestMyList2.java:67)
        at TestMyList2.main(TestMyList2.java:9)
Press any key to continue . . .
public MyIterator iterator(){ return new MyArrayListIterator();}  
private class MyArrayListIterator implements MyIterator
{
          private ListIterator AL;
          public void MyArrayListIterator()
          {
               AL=data.listIterator();
          }
          public boolean hasNext()
          {
	   return AL.hasNext();
          }
 
          public Object next()
          {
               return AL.next();
          }
 
          public void remove()
          {
               AL.remove();
          }
}

Open in new window

CEHJ

I see you're making progress ;-) Make sure you've created 'data'
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
>> Make sure you've created 'data'

huh?
CEHJ

You have a (real) List called 'data'. How and where do you create it?
yunji1

ASKER
You really haven't looked at any of my code have you? How do you answer questions or give advice without all of the information?

For the sake of just lobbing bombs across the river, I am closing this thread. This thread is done. I wouldn't recommend this thread to ANYONE unless they wanted to get examples from the code provided. I am no further than when I opened it.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
yunji1

ASKER
This is the final result for anyone that needs a good example of how it was all implemented. Good Luck.
import java.util.*;
 
class MyArrayList implements MyList
{
     private List data = new ArrayList();
     final int NOT_FOUND = -1;
     private int incIndex = 0;
 
     public void clear()
     {
         data.clear();
     }
 
     //Returns the current number of elements in the list.
     public int size()
     {
          return data.size();
     }
 
     //Returns true if no elements, false otherwise.
     public boolean isEmpty()
     {
          return data.isEmpty();
     }
 
     //Returns true if this list contains the specified element,
     //false otherwise.
     public boolean contains(Object obj)
     {
          return data.contains(obj);
     }
 
     //Adds element to end of list. Increases size() by 1.
     //Only need to return true, since this assignment requires that this
     //operation always succeeds.
     public boolean add(Object obj)
     {
          return data.add(obj);
     }
 
     //Removes first occurrence of element if present.
     //Returns true if collection modified (size decreases by one),
     //false otherwise.
     public boolean remove(Object obj)
     {
         incIndex = data.indexOf(obj);
	 if(incIndex != NOT_FOUND)
	 {
	      data.remove(incIndex);
              return true;
	 }
	 else
	 {
	      return false;
         }
     }
 
     //Returns a MyIterator object, default initialized to refer to the
     //first element.
 
     public MyIterator iterator()
     {
          return new MyArrayListIterator();
     }
     private class MyArrayListIterator implements MyIterator
     {
          private ListIterator AL;
 
          public MyArrayListIterator()
          {
               AL=data.listIterator();
          }
 
          //Returns true if the iterator has more elements.
          public boolean hasNext()
          {
	    return AL.hasNext();
          }
 
          //Returns the next element in the list.
          public Object next()
          {
               return AL.next();
          }
 
          //Removes from the underlying collection the last element
          //returned by the iterator (its currently positioned element).
          public void remove()
          {
               AL.remove();
          }
     }
 
     //Returns the element at index, null if not present or
     //index is out of range.
     public Object get(int index)
     {
          return data.get(new Integer(index));
     }
 
     //Replaces the element at the specified index in this list
     //with the specified element.
     //Returns the original element at index, null if not present
     //or index in out of range.
     public Object set(int index, Object obj)
     {
          return data.set(index,obj);
     }
 
     //Returns the index in this list of the first occurrence of the
     //specified element, or -1 if this list does not contain this element.
     public int indexOf(Object obj)
     {
         return data.indexOf(obj);
     }
}

Open in new window

CEHJ

>>You really haven't looked at any of my code have you?

On the contrary. After your first postings i downloaded all your code and corrected it. How could i know what's wrong without looking at it?
yunji1

ASKER
I would like to thank you for all of your help. It was not your fault that I was unable to understand the obvious solution that was in front of me. In the event that this happens again, I will look for a translator so that I don't have to bother you or anyone else as much. :)
âš¡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
yunji1

ASKER
>> After your first postings i downloaded all your code and corrected it.

Awesome...........HOURS and HOURS of my life that I can never get back. Thank you for the lesson.