Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

head first java 2nd edition GameHelper class getUserInput(String ) not defined


  • Please log in to reply
1 reply to this topic

#1 jkv1255

jkv1255

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:05:44 PM

Posted 27 October 2015 - 10:41 PM

String guess=helper.getUserInput("enter"); this statement has an error as eclipse says, the method getUserInput(String) is undefined for type GameHelper.
 
this has made me gone mentally irritated in finding out what is the error. 
please help me guys.
 thanks a lot
 
    import java.io.*;
import java.util.*;
 public class SimpleDotComTestDrive1 {
        public static void main(String[] args) {
int numOfGuesses=0;
GameHelper helper=new GameHelper();
SimpleDotCom1 dot=new SimpleDotCom1();
int randomNum=(int)(Math.random()*5);
int locations[]={randomNum, randomNum+1,randomNum+2};
dot.setLocation(locations);
boolean isAlive=true;
while(isAlive==true){
String guess=helper.getUserInput("enter");
String result=dot.checkYourself(guess);
numOfGuesses++;
if(result.equals("kill")){
isAlive=false;
System.out.println("u took"+numOfGuesses+"guesses");
}
}
}
}
class SimpleDotCom1{
int [] cellLocations;
int numOfHits=0;
void setLocation(int[] locations){
cellLocations=locations;
}
public String checkYourself(String userGuess){
int guess=Integer.parseInt(userGuess);
String result="miss";
for(int cell: cellLocations){
if(guess==cell){
result="hit";
System.out.println("1 numOfHits"+numOfHits);
numOfHits++;
System.out.println("2 numOfHits"+numOfHits);
break;
}
}
if(numOfHits==cellLocations.length){
result="kill";
}
System.out.println(result);
return result;
}
}
   class GameHelper
{
public String getUserlnput(String prompt)
{
String inputLine = null;
System.out.print(prompt +" ");
try 
{
BufferedReader is = new BufferedReader (
new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length () == 0)
 
return null;
 
else{}
catch (IOException e) 
{
System.out.println("IOException: " + e);
}
return inputLine;
}
}
 
 
 


BC AdBot (Login to Remove)

 


#2 jkv1255

jkv1255
  • Topic Starter

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Local time:05:44 PM

Posted 27 October 2015 - 11:17 PM

topic closed, error was in method definition, i typed small L instead of capital i

 

thanks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users