You are on page 1of 4

GUESSING GAME

Prompt user to input their guess.

If input is correct player proceeds to next level and guess the next number:
If user entered wrong number, system shows scores and asks the user if he want to play again:
If no, program exits.

CODES:

/*members:
* Nachor,John Reymart P.
* Senorin,Nica E.
* Dizon, Claire B.
* De Grano, Katlyn I.
* Lumbres, Majie E.
*
*
*
*/
import java.util.Scanner;
public class Finals {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int deter=1, ans;
int mystnum;
int level = 1;
System.out.println("GUESS THE MYSTERY NUMBER:");
do{
mystnum=(int)(Math.random()*10);
System.out.println("Level "+level+"(Choose between 0 - 9)");
System.out.println("(FOR TESTING PURPOSES: Mystery number = "
+mystnum+")");
System.out.println("Input guess:");
ans = in.nextInt();
if(ans==mystnum)
level++;
else
deter=0;
}while(deter != 0);
System.out.println("Score: "+level);
Finals.quit();
in.close();
}
public static void quit(){
Scanner in = new Scanner(System.in);
System.out.println("Do you want to play again? Y/N");
String q = in.nextLine();
switch(q){
case "Y":
case "y":
Finals.main(null);
break;
case "N":
case "n":
System.out.println("Bye, quitter!");
System.exit(0);
break;
default:
Finals.quit();
break;
}
in.close();

}
}

You might also like