Friday, January 30, 2015

Java project

This code picks a random number between 1 and 100, and sets it to numberToGuess. It also assigns three other variables, win, guess and numberOfTries. Every time a guess is made, that integer is set to the guess value, which is then checked if it is equal to the numberToGuess. If it is not the numberToGuess, then win remains false and two new methods are run. The first method checks if the guess is greater than the numberToGuess. If true, then it will tell you that your guess is too high. Else, if the guess is less than the numberToGuess, it will tell you that your guess is too low. Every time a guess is made, one is added to the numberOfTries. When the guess is equal to the randomly assigned numberToGuess, the boolean value win is set to true and the build ends after telling you the numberToGuess and the numberOfTries.



No comments:

Post a Comment