import java.util.*; public class HelloWorld
{
public static void main(String []args)
{
int score =0;
int noOfGames =0;
int noOfCorrectedGames =0;
String name;
int age;
int ran=0;
int guessno=0;
int round_count=0;
Scanner keyboard = new Scanner(System. in);
System.out.println("Enter your Name:");
name = keyboard.next();
System.out.println("Enter your age in Numeric:");
age = keyboard.nextInt();
//System.out.println("Random value is " + ran);
if(age<7 && age>=4)
{
ran=randomNumberInRange(1, 20);
}
else if(age<12 && age>=7)
{
ran=randomNumberInRange(1, 25);
}
else if(age>=12)
{
ran=randomNumberInRange(1, 30);
}
else if(age<4)
{
System.out.println("You are Strictly prohibited to use this " +
"application including the laptop");
System.exit(0);
}
for(int y=1;y<10;y++) //Play Till you Die
{
noOfGames = y;
if(age<7 && age>=4)
{
ran=randomNumberInRange(1, 20);
}
else if(age<12 && age>=7)
{
ran=randomNumberInRange(1, 25);
}
else if(age>=12)
{
ran=randomNumberInRange(1, 30);
}
else if(age<4)
{
System.out.println("You are Strictly prohibited to use this " +
"application including the laptop");
System.exit(0);
}
for (int i=1;i<11;i++) // every student get a 10 attempts
{
round_count=i;
System.out.println("Guess the Magical No(Numeric):");
guessno = keyboard.nextInt();
if(guessno==ran) //If Correct Answer
{
if(i>=1 && i<=3)
{
score=5;
}
else if(i>=4 && i<=6)
{
score=3;
}
else if(i>=7 && i<=10)
{
score=1;
}
noOfCorrectedGames++;
System.out.println("-------------------GAME OVER --------------------");
System.out.println("Do you want to Play again? Enter P; Do you want to Exit? Enter E; :");
String result = keyboard.next();
if(result.equals("E"))
{
print_deadgame_results();
System.exit(0);
}
else
{
break;
}
}
else //If Wrong Answer
{
if(ran >guessno)
{
System.out.println("GO HIGHER !");
}
else if(ran <guessno)
{
System.out.println("GO LOWER !");
}
}
}
if(round_count==10)
{
System.out.println("-------------------GAME OVER --------------------");
System.out.println("Do you want to Play again? Enter P; Do you want to Exit? Enter E; :");
String result = keyboard.next();
if(result=="E")
{
print_deadgame_results();
System.exit(0);
}
else
{
}
}
}
print_deadgame_results();
}
public static int randomNumberInRange(int min, int max)
{
Random random = new Random();
return random.nextInt((max - min) + 1) + min;
}
public static void print_deadgame_results()
{
System.out.println("=================== Final Score =======================");
System.out.println("Total number of games played : " + noOfGames);
System.out.println("Total number of games where correct guesses were made : " +noOfCorrectedGames);
System.out.println("Hello "+ name +", you scored "+ score +" out of possible "+ noOfGames +".");
}
}
HelloWorld.java:160: error: cannot find symbol
System.out.println("Total number of games played : " + noOfGames);
^
symbol: variable noOfGames
location: class HelloWorld
HelloWorld.java:161: error: cannot find symbol
System.out.println("Total number of games where correct guesses were made : " +noOfCorrectedGames);
^
symbol: variable noOfCorrectedGames
location: class HelloWorld
HelloWorld.java:162: error: cannot find symbol
System.out.println("Hello "+ name +", you scored "+ score +" out of possible "+ noOfGames +".");
^
symbol: variable name
location: class HelloWorld
HelloWorld.java:162: error: cannot find symbol
System.out.println("Hello "+ name +", you scored "+ score +" out of possible "+ noOfGames +".");
^
symbol: variable score
location: class HelloWorld
HelloWorld.java:162: error: cannot find symbol
System.out.println("Hello "+ name +", you scored "+ score +" out of possible "+ noOfGames +".");
^
symbol: variable noOfGames
location: class HelloWorld