This fun and easy project "Guess the Number" is a short Java project that allows the user to guess the number generated by the computer and involves the following steps:
- The system generates a random secret number from a given range, say 1 to 100.
- The user is prompted to enter their guess number in a displayed dialogue box.
- The computer then tells if the entered number matches or is higher/lower than the secret number.
- The game continues until the user guesses the secret number.
Inside the src
folder
Compile
javac GuessingGame.java
Run
java GuessingGame
You can incorporate further details:
- Improving the code syntax, for example:
- Add error handling for non-integer user input.
- Use constants for the minimum and maximum values instead of hardcoding them.
- Use a do-while loop
- Add comments to explain the purpose of the code and each method.
- Limiting the number of attempts.
- Playing another round.
- Choose a difficulty level
- Displaying score.
- Giving points based on the number of attempts.
- Your ideas?