My code is as follows, I'm only having a single error come up when I attemtp to compile, but I've spent 45 minutes trying to figure it out by searching Google and my textbook by I can't figure out what I'm doing wrong. The program is designed so that the user plays a game where the computer picked a number from 1-100 and tells higher or lower after each guess.
"Error: cannot find symbol variable reader" This is related to line 37, which is at the start of the method called "Guess()". I've tried declaring reader as a String variable, along with many other potential solutions. Any help is appreciated, thanks.
import java.io.*;
import java.util.*
;
public class Guessing
{
private static int Rand;
private static int Guess;
private static int Counter;
public static void main (String Args[]) throws IOException
{
// This section calls the initial two methods.
// Other methods will be called from within if statements.
Rand();
Guess();
}
public static void Rand() throws IOException
{
// This gives a random integer from 1-100.
Random Randomizer = new Random();
Rand = Randomizer.nextInt(100) + 1;
}
public static void Guess() throws IOException
{
// Obtain the user's guess.
Guess = reader.readInt("Guess what integer the computer picked between 1 and 100: ");
// Three checks to make sure that the entered number is valid.
if (Guess > 100){
System.out.println("Your guess should be less than or equal to 100.");
Guess();}
if (Guess < 1){
System.out.println("Your guess should be greater than or equal to 1.");
Guess();}
if (Guess % 1 != 0){
System.out.println("Your guess must be an integer.");
Guess();}
// Move to the next method.
Outcome();
}
// This method determines whether the number guessed is higher or lower than the random 1-100.
public static void Outcome() throws IOException
{
if (Guess == Rand)
Win();
else
if (Guess > Rand){
System.out.println("Your guess was too high, try again!");
Counter++;
Guess();
}
else{
if (Guess < Rand){
System.out.println("Your guess was too low, try again!");
Counter++;
Guess();
}
}
}
// This method occurs when the user guesses the correct number
public static void Win() throws IOException
{
System.out.println("Congratulations, You Win!");
System.out.println("It took you " + Counter + " guesses!");
}