For this part you will make a program that can play a simple number guessing gam
ID: 3662428 • Letter: F
Question
For this part you will make a program that can play a simple number guessing game. You will think of a number and the computer will try to guess it, with help from you. It should start by asking for a range in which to find your number. Then, when it starts guessing, the only hints you are allowed to give are "l" (too low), "h" (too high), and "c" for a correct guess. It will repeatedly guess numbers until it finds the correct one. You should make your program guess your number in as few steps as possible. Some details: The range is inclusive, so if you say the range is "1200 to 1400" it could guess the min and max values 1200 and 1400" It should work with negative numbers If it is obvious what the answer is, it should print it and exit All of your code should go inside "GuessingGame.javaA (it's in the setup folder) Here are some examples:Explanation / Answer
Class GuessingGame
{
public static void main(String args[])
{
int Low,High,Mid;
char ch;
System.out.prinln(“Enter Low Range”);
Low=Integer.parseInt(br.readLine());
System.out.prinln(“Enter High Range”);
High=Integer.parseInt(br.readLine());
System.out.println(“Type ’h’ for too high , ’l’ for ’too low ’ and ’c’ if I got t right”)
while(1)
{
Mid=(High+Low)/2;
System.out.println(“IS it “+ Mid +”?”);
Ch=br.read();
If (Ch==’h’)
Low=Mid;
If (Ch==’l’)
High=Mid;
If (Ch==’c’)
{
System.out.println(“I always win”);
break;
}
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.