DEV Community

Cover image for Number Guessing Game using Java ๐ŸŽฎ
Safvan P
Safvan P

Posted on

Number Guessing Game using Java ๐ŸŽฎ

The game contains 5 players. One Umpire, one Guesser and three Players.
The guesser guesses a number between 1 and 10 and tell it to the umpire secretly. The remaining 3 players try to predict the number guessed by the guesser.
The one who predicts the number accurately is the winner of the game.
If more than one Player predicts the right number, all of them are winners.

Class Diagram for the game:

Image description

The guessing game involves an โ€˜Umpireโ€™ object , 'Guesser' object and three โ€˜playerโ€™ objects. All the objects are created by instantiating the above 3 classes.

Features Included in this game:

โ‡’ Restricted the all the players and guesser to guess a number between 1 and 10. Even if they predict/guess a number out of this range, then the program will prompt to re-enter the input until they're choosing a value with in allowed range.

Image description

Image description

โ‡’ added a counter to print player numbers in the console.

โ‡’ Print summary of the game after finding the winner. The summary includes Accuracy of prediction of players who lost the game.
Accuracy is displayed in terms of, how close number predicted by players towards the number guesser by guesser.

Image description


๐Ÿ–ฅThe source code of the game is uploaded on GitHub:
https://bit.ly/3vGfAXo

๐ŸŒŽConnect with me on LinkedIn : https://www.linkedin.com/in/safvan-p/

Top comments (0)