/**
* Write a description of class guessingGame here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.lang.Math;
public class guessingGame
{
public static void main(String args[]){
{
String playAgain; //useless variable that Mr. Memo used to start us off in this assignment
int num; //another variable that peter created to store another scanner variable
int guessInt; //a variable to store user's input
boolean why = true; //actuator for the while loop
Scanner scan = new Scanner(System.in);
System.out.println("This is the worst guessing game."); //a humorous start to a starkly great game
while(why==true){
int rnd = (int)(Math.random()*10+1); //randomly generates a random number between 1 and 10
for(int i=0;i<3;i++){ //FOR loop used to easily repeat the process of guessing
System.out.println("Please guess a number between 1 and 10. (including 1 and 10)");
//System.out.println(rnd);//this line was used in testing whether the program worked
guessInt = scan.nextInt();//takes in user's guess
if(guessInt==rnd){
System.out.println("Congratulation, you are good at a horrid text-based game, indeed.");
System.out.println("Answer: "+rnd);//shows user the answer
i=3;//to instantly end the program
}
else{
System.out.println("I know life is hard and tough sometimes, but you have to push past that and guess the correct number.");
if(i==1){
System.out.println("Ok, I believe you can do it. don't give up jsut quite yet. Try again :D");
}
if(i==2){
System.out.println("Sigh, you know, i'll jsut give you the correct answer: "+rnd);//shows user the correct answer
}
System.out.println("Your last guess: "+guessInt);//shows the user their last guess
}
}
System.out.println("Do you want to play this clearly amazing game again? (type 1 to play again and 2 to exit)");
num = scan.nextInt(); //above is the humorous end to such an amazing game
while(num!=2 && num!=1){
System.out.println("please ENTER a CORRECT #!!!!!");
num = scan.nextInt();
}
if(num==2){
why = false;//actuator switch to end the program
}
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.