# Thread: Stupid guess method....

1. Senior Member
Join Date
Jun 2013
Posts
136
Rep Power
0

## Stupid guess method....

I have a class assignment to create a random number game and I am having issues with one of the methods....I have looked at this so much my brain feels like a kaleidoscope......any help would be so appreciated. The more I am in this class the more confused I get....

Here are the directions for this method:
iv. guess method
1. Takes in an integer as a parameter representing a new guess.
2. Compares the new guess with the answer and generates and returns a String representing an appropriate response.
3. The response is based on:
a. The relation of the guess and answer (too high, too low or correct).
b. The comparison of difference between the current guess and the answer and the previous guess and the answer. (warmer, colder)
c. Guess out of range error, if the guess is not between 0 and the max number (inclusive) (see sample run below)
d. User has taken too many guess because numGuessesTaken is greater than maxGuessesAllowed. If this is the case set isGameOver to true.

Here is what I have for the method:

PHP Code:
```		public int guess(int newGuess)
{

String response;
differential = Math.abs(newGuess-answer);
int newDifferential = Math.abs(answer - differential);
Scanner keyboard = new Scanner(System.in);
boolean firstGuess;

if (numGuessesTaken = 0)
{
firstGuess = true;
}
else
{
firstGuess = false;
}

if (numGuessesTaken <= maxGuessesAllowed)
{
if(answer == newGuess)
{
response = "Correct.  Would you like to play again, enter Y for yes, N for no.";
gameOver=true;

}
else if(answer < newGuess)
{
response = "Too low";
}
else if(answer > newGuess)
{
response = "Too high";
}
else if(answer > 100 || answer < 1)
{
response ="Guess out of range, the guess must be between 1 and 100.";
}

if(firstGuess = false)
{
if (newDifferential< differential)
{
response = "Warmer";
}
else
{
response = "Colder";
}
}
}
else
{
gameOver=true;
response = "Would you like to play again, enter Y for yes, N for no.";
}
}```
Here are the errors I keep getting:
GuessingGame.java:99: error: incompatible types (actually line 10 since I did not put my entire code up there)
if (numGuessesTaken = 0)
^
required: boolean
found: int

2. Member
Join Date
Jun 2013
Posts
60
Rep Power
0

## Re: Stupid guess method....

= is an assignment operator not a comparison. Try ==

3. Senior Member
Join Date
Jun 2013
Posts
136
Rep Power
0

## Re: Stupid guess method....

That was totally it! Thanks.

Now I have a whole new error
GuessingGame.java:146: error: missing return statement (actually line 58 since I did not put my entire code up there)
}
^
1 error

I have checked and double checked and all my opening brackets have corresponding closing brackets.....what am I missing here? I will admit the whole "nesting" thing has me a bit confused (like when to do it and all) could that be my issue?

4. ## Re: Stupid guess method....

Your method promises to return an int but nowhere in the code I can find a return <an int>; statement. The compiler also noticed that fact and started to complain ...

kind regards,

Jos

5. Senior Member
Join Date
Jun 2013
Posts
136
Rep Power
0

## Re: Stupid guess method....

Can you dumb that down for me? newGuess will be user input when I write the tester program.

Also, I am struggling with this part:

2. Compares the new guess with the answer and generates and returns a String representing an appropriate response.

If at the end of the method I put

return response;

I get the incompatible types error...required int found string.

6. ## Re: Stupid guess method....

Please go through the Forum Rules, particularly the third paragraph.

db

7. Senior Member
Join Date
Jun 2013
Posts
136
Rep Power
0

## Re: Stupid guess method....

Thanks for all the help....got this part figured out....now to work on the tester.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•