[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

size() and get() problems in while loop

Posted on 2004-10-27
8
Medium Priority
?
207 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:bnblazer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:fredwangus
ID: 12430223
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
 
LVL 1

Author Comment

by:bnblazer
ID: 12430238
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
 
LVL 1

Author Comment

by:bnblazer
ID: 12430251
I forgot to include the import in the code above.

import java.util.ArrayList;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12430270

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

Author Comment

by:bnblazer
ID: 12430322
That works, and I have awarded the points - thank you.  If possible, could you explain it a bit?

Thanks,
Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 12430351
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
 
LVL 1

Author Comment

by:bnblazer
ID: 12430399
Thank you.  It is greatly appreciated.

Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 12430427
no worries :)
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question