Lab 06 - Number Guessing Game
Assignments
Create a number-guessing game that corresponds to this output:
Choose a number between 1 and 100:
50
Too high.
Choose a number between 1 and 50:
38
Too low.
Choose a number between 38 and 50:
46
Correct.
Game Over.
A few things to note:
-
The range given to the user starts at 1 - 100 and changes after each guess.
-
There isn't a limit to the number of times the user can guess. They might get it in the first guess, or the 30th guess.
-
To create a random number in Java, you can use:
import java.util.Random;
...
Random rand = new Random();
int upperBound = 100;
int randomNumber = rand.nextInt(upperBound + 1);
- Your code should use at least one method, preferably more. Likely candidates include a function to generate the random number without a certain bounds, a method to evaluate a guess and print the results, etc...
Restrictions:
-
Your code must use loops.
-
Your code must use a random number.
-
Your code must use at least one method aside from
main
andrun
.
Submission
To submit your assignment, follow the instructions for code submission.