Our program must create a guessing game that asks the user what the range they want to game to be and how many guesses they want. Once that is done it askes the user to make a guess and based on the guess its supposed to say Hot if it is within 10% of the answer, Warm if it is withing 25%, and Cold if it is outside 25%.
Here is what I have so far,
public class GuessingGame1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner (System.in);
Random generator = new Random();
int guesses;
int guessNum = 0;
double difference = 0;
int answer;
double guess = 0;
String another = "y";
boolean flag = false;
boolean anotherFlag = true;
System.out.print("Please enter a number to indicate the range of the game (10,20,30)");
guessNum = keyboard.nextInt();
System.out.println("How many guesses should I allow?");
guesses = keyboard.nextInt();
System.out.println("Let's Play. I've chosen my number.");
while(anotherFlag){
answer = generator.nextInt(guessNum) + 1;
System.out.println("It's a whole number between 1 and " + guessNum + (": "));
flag = false;
guess = keyboard.nextInt();
if(guess > answer)
{
difference = guess - answer;
}
else if (guess < answer)
{
difference = answer - guess;
while(!flag)
{
if(guess == answer)
{
System.out.println("You guessed correctly! Good Job");
flag = true;
}
else if(difference / guessNum <= .10)
{
System.out.println("Hot! Try Again: ");
}
else if(difference / guessNum > .10 || guessNum <= .25)
{
System.out.println("Warm! Try Again: ");
}
else
{
System.out.println("Cold! Try Again ");
}
guess = keyboard.nextInt();
}
System.out.println();
System.out.println("Would you like to play again? (y/n)");
another = keyboard.next();
if(another.equalsIgnoreCase("y") == true)
{
anotherFlag = true;
}
else
{
anotherFlag = false;
}
}
}
}
}
I cant seem to get the hot warm and cold thing to work, and how do i impliment the number of guesses the user gets?