## import false){ // This while loop keeps repeating

import java.util.Scanner; // import scannerimport java.util.Random;  // import random classimport java.lang.System;////   Taylor Rochon//   Computer Science Final Culminating Project//   January 2018//public class NumGuessingGame {    public static void main (String args){        //                          *INTRO TO GAME*        //        // User will guess a random number of any length and will keep guessing and        // using the hints provided (whether it is too high or low) and the program        // will keep track of how many times user has guessed and at the end of the        // game it will display win or lost and how many guesses it took to find        // the right number.              System.out.print(“Welcome.
“);        System.out.print(“You are now playing a game that will give you a random generated number between 1 and the number you chose
“);        System.out.print(“Choose wisely:

“);        Scanner scan = new Scanner(System.in);  // This is the number the user will input of the start of the game so the computer knows the limit on where it generates a number        int max;        max = scan.nextInt();        Random randomNum = new Random();        int num = randomNum.nextInt(max);        int guesses = 0; // This number will change (or stay the same) depending on how many guesses the user takes to find the unknown number        Scanner input2 = new Scanner(System.in);        int guess;        boolean playerWin = false;        while (playerWin == false){  // This while loop keeps repeating until the user guesses the right number            System.out.print (”
Now start guessing between 1 and “+max+”:
“);            guess = input2.nextInt();            guesses++; // Refers back to tries = 0 will keep adding 1 to the guess count until the user gets it right            if (guess == num){                playerWin = true; // This is the first thing the input number will go through to check if it is a winning number or not                                  // If the number is guessed first try playerWin = true and the game will end if not it will keep going through the loop                                              }            else if(guess < num){                System.out.print(" Your guess was too low, try again!");                                 // Second phase of the loop the number is checked to see if it was too low or too high                                 // If too low the player will be prompted to guess again            }            else if(guess > num){                System.out.print(”
Your guess was too high, try again!”);                                 // Third phase of the loop the number is checked to see if it was too low or too high                                 // If too low the player will be prompted to guess again            }        }                                 // When the user gets the correct number the text below will print out        System.out.print(“Congratulations!! You have won the game
“);        System.out.print(“Wow!! It only took you ” +guesses+ ” guesses to get the correct number.                                                   “);               }}

We Will Write a Custom Essay Specifically
For You For Only \$13.90/page!

order now
x

Hi!
I'm Johnny!

Would you like to get a custom essay? How about receiving a customized one?

Check it out