size() and get() problems in while loop

I have a method that I am working on (not a class assignment), and my relative newbie status is getting in the way of figuring out what is going wrong.  Here is the code snippet:

private void startPlaying() {
       while (!dotComsList.isEmpty()) {
           GuessList thisList = new GuessList();
           String userGuess = helper.getUserInput("Enter a guess:");
           
           if (userGuess.equals("list")) {
               System.out.println("Retrieving your list of guesses:");
               for (int i = 0; i < thisList.size(); i++) {
                   System.out.println("Guess # " + i + "=" + thisList.get(i));
               }
           } else {
               checkUserGuess(userGuess);
               thisList.storeGuess(userGuess);
           }
       }
       finishGame();
    }

My problem is with the size() and get() in the for loop.  I keep getting these errors:
The method size() is undefined for the type GuessList
      The method get(int) is undefined for the type GuessList

I am importing java.util, and these methods work elsewhere in the class, but I can't figure out why they wont work here, and of course what to do about it.

Any help is greatly appreciated.

Thanks,
Brian
LVL 1
bnblazerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fredwangusCommented:
Did your class GuessList implemented interface List or sub classes of List?
Guess u need to do so if u want to use size and get functions.
0
bnblazerAuthor Commented:
GuessList uses ArrayList.  Here is the code:

public class GuessList {
    private ArrayList guesses = new ArrayList();
   
    public void storeGuess(String userGuess) {

        if (!guesses.contains(userGuess)) {
           guesses.add(userGuess);
        }
    }

    /**
     * @return Returns the guesses.
     */
    public ArrayList GetGuessList() {
        return guesses;
    }
    /**
     * @param guesses The guesses to set.
     */
    public void setGuesses(ArrayList guesses) {
        this.guesses = guesses;
    }
}
0
bnblazerAuthor Commented:
I forgot to include the import in the code above.

import java.util.ArrayList;
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

objectsCommented:

      for (int i = 0; i < thisList.GetGuessList().size(); i++) {
             System.out.println("Guess # " + i + "=" + thisList.GetGuessList().get(i));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bnblazerAuthor Commented:
That works, and I have awarded the points - thank you.  If possible, could you explain it a bit?

Thanks,
Brian
0
objectsCommented:
size() and get() are methods of the ArrayList, not methods of your GuessList.
So you need to make the size() and get() calls on the the ArrayList which is accessible via the GetGuessList() method of GuessList.
0
bnblazerAuthor Commented:
Thank you.  It is greatly appreciated.

Brian
0
objectsCommented:
no worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.