I am working on a project where you make a code that has the computer guess a random number, and then the user says if that number is higher or lower. Then the computer is supposed to change its parameters based on what the user says. For example if it guesses 33 and you say too low and it says 74 and it says too high, then the next number generated will be between 33 and 74. My problem is, I can make the range get higher with using the rFinder variable and such when UserAnswer=2 in the RepeatedGuess method. But, though trying many things, I can't get a range that is dynamic or that changes throughout the code. Am I approaching this completely the wrong way? Any suggestions would be helpful.
import java.util.Scanner;
import java.util.Random;
public class Proj72 {
private static int UserAnswer;
private static int maximum = 100;
private static int minimum = 0;
private static int rFinder;
private static Random generator = new Random();
private static Scanner reader = new Scanner(System.in);
private static int guess = generator.nextInt(100);
public static void main(String[] args) {
FirstGuess();
RepeatedGuesses();
Correct();
}
private static void FirstGuess() {
System.out.print(guess + ": Is this your number? Enter 1 For Yes or enter 2 for Too Low or enter 3 for Too High:");
}
private static void RepeatedGuesses() {
while (1 != UserAnswer) {
UserAnswer = reader.nextInt();
if (2 == UserAnswer) {
rFinder = (int)(generator.nextInt(100 - guess));
guess = rFinder + guess;
System.out.print(guess + ": Is this your number? Enter Yes or enter Higher or enter Lower:");
} else if (3 == UserAnswer)
break;
}
}
private static void Correct() {
if (1 == UserAnswer) {
System.out.print("I got it!");
}
}
}