Question
Write a java program to play the game of Guessing Number - 2 Players. Firstly, player one(P1) proposes a number N, the program generates a
Write a java program to play the game of "Guessing Number - 2 Players". Firstly, player one(P1) proposes a number N, the program generates a random number between 0 to N. Then, player two(P2) has 1 chance to guess the number. If P2 hits the number, P2 wins. Otherwise, P2 can either proposes a new number N' (N' <= N) and let the P1 guesses the new generated number, or doesn't propose any new number and let the P1 guesses the previous random number. Then, P1 has 1 chance to guess. If P1 hits the number, P1 wins. Otherwise, P1 can either proposes a new number N'' (N'' <= N (or N')) and let the P2 guesses the new generated number, or doesn't propose any new number and let the P2 guesses the previous random number. Keep repeating until one of players wins the game.
Example:
(P1) - Welcome P1, please input a random seed:
(P1) - 5
(P2) - P2, please input your guess(0 - 5):
(P2) - 1
(P2) - Incorrect. Please select "ONE. Continue guessing; TWO. Generate a new number
(P2) - ONE
(P1) - P1, please input your guess(0 - 5):
(P1) - 2
(P1) - Incorrect. Please select "ONE. Continue guessing; TWO. Generate a new number
(P1) - TWO
(P1) - 4
(P2) - P2, please input your guess(0 - 4):
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started