Question

For this assignment, you will write a program that guesses a number chosen by your user....

For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number.

When the program starts up, it outputs a prompt asking the user to guess a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or no answer. For example:

Is your number evenly divisible by 3? (Yes or No)

The user will enter “Yes” or “No” to each question. When the program is sure it knows the user’s number it outputs the number. For example:

Your number is 9.

To receive full credit, your program must always guess the user’s number in less than five questions.

This assignment will be completed in two parts:

1. You will write and turn in properly indented pseudo-code for this assignment. Be sure you keep a copy of the pseudo-code you turn in to help you in writing the program.

2. You will create your guessing game program, and verify that it works properly on all possible inputs. Your program must be properly documented and all if and else statements must be indented properly.

I need the algorithm and pseudocode in java please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PART 1.

Declare Function GuessGame:

       Ask user if number is EVEN or NOT?
       if EVEN
         
           //Guess if number is from [2,4,6,8,10]
           Ask user if number is less than 5
              
               if less than 5
               //Guess if number is from [2,4]
               Ask user if number is less than 3  
                  
                   if less than 3
                   //Guess if number is from [2]
                       print NUMBER 2
                  
                   if NOT less than 3
                   //Guess if number is from [4]
                       print NUMBER 4
              
               if NOT less than 5
               //Guess if number is from [6,8,10]
               Ask user if number is less than 7
                  
                   if less than 7
                   //Guess if number is from [6]
                       print NUMBER 6
              
              
                   if NOT less than 7
                   //Guess if number is from [8,10]
                   Ask user if number is less than 9
                  
                       if less than 9
                       //Guess if number is from [8]
                           print NUMBER 8
                      
                       if NOT less than 9
                       //Guess if number is from [10]
                           print NUMBER 10

          
       if NOT EVEN
         
           //Guess if number is from [1,3,5,7,9]
           Ask user if number is less than 4
              
               if less than 4
               //Guess if number is from [1,3]
               Ask user if number is less than 2  
                  
                   if less than 2
                   //Guess if number is from [1]
                       print NUMBER 1
                  
                   if NOT less than 2
                   //Guess if number is from [3]
                       print NUMBER 3
              
               if NOT less than 4
               //Guess if number is from [5,7,9]
               Ask user if number is less than 6
                  
                   if less than 6
                   //Guess if number is from [5]
                       print NUMBER 5
              
              
                   if NOT less than 6
                   //Guess if number is from [7,9]
                   Ask user if number is less than 8
                  
                       if less than 8
                       //Guess if number is from [7]
                           print NUMBER 7
                      
                       if NOT less than 8
                       //Guess if number is from [10]
                           print NUMBER 9
End Function

PART 2.

//Code in Java Programming Language

import java.io.*;
import java.util.Scanner;

class GuessGame {
   public static void main (String[] args) {
   Scanner in = new Scanner(System.in);
       String answer;
       System.out.println("Is your number even? (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [2,4,6,8,10]
       if(answer.equals("Yes"))
       {
       System.out.println("Is your number less than 5 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [2,4]
       if(answer.equals("Yes"))
       {
       System.out.println("Is your number less than 3 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [2]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 2.");
       }
      
       //Guess if number is from [4]
       else if(answer.equals("No"))
       {
       System.out.println("Your number is 4.");
       }
       }
      
       //Guess if number is from [6,8,10]
       else if(answer.equals("No"))
       {
       System.out.println("Is your number less than 7 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [6]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 6.");
       }
      
       //Guess if number is from [8,10]
       else if(answer.equals("No"))
       {
       System.out.println("Is your number less than 9 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [8]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 8.");
       }
      
       //Guess if number is from [10]
       else if(answer.equals("No"))
       {
       System.out.println("Your number is 10.");
       }
       }
       }
       }
      
//Guess if number is from [1,3,5,7,9]      
       else if(answer.equals("No"))
       {
       System.out.println("Is your number less than 4 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [1,3]
       if(answer.equals("Yes"))
       {
       System.out.println("Is your number less than 2 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [1]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 1.");
       }
      
       //Guess if number is from [3]
       else if(answer.equals("No"))
       {
       System.out.println("Your number is 3.");
       }
       }
      
       //Guess if number is from [5,7,9]
       else if(answer.equals("No"))
       {
       System.out.println("Is your number less than 6 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [5]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 5.");
       }
      
       //Guess if number is from [7,9]
       else if(answer.equals("No"))
       {
       System.out.println("Is your number less than 8 (Yes or No)");
       answer = in.next();
      
       //Guess if number is from [7]
       if(answer.equals("Yes"))
       {
       System.out.println("Your number is 7.");
       }
      
       //Guess if number is from [9]
       else if(answer.equals("No"))
       {
       System.out.println("Your number is 9.");
       }
       }
       }
       }
   }
}

-------------------------------------------------------------------------------------------------------------------------------------------------------
Working hard on improving the quality of solutions I deliver. A
Thumbs Up ? is appreciated. Thanks!
For queries leave a comment, I will be most happy to help.
?

Add a comment
Know the answer?
Add Answer to:
For this assignment, you will write a program that guesses a number chosen by your user....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAM: Guessing Game Objective The student will write an individualized program that utilizes conditional flow...

    JAVA PROGRAM: Guessing Game Objective The student will write an individualized program that utilizes conditional flow of control structures in Java. Specifications For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to...

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

  • Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it)...

    Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7 tries or lower. Initialize a variable that represents the lowest possible number to 0 (what type should this be?) Initialize a variable that represent the highest possible number to 100 (what type should this be?) Initialize a Boolean variable that represents if we’ve achieved the correct guess to false Initialize a variable in which to...

  • Write a program that allows a user to play a guessing game. Pick a random number...

    Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Write a program to play "guess my number". The program should generate a random number between...

    Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...

  • Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent...

    Using C programming REQUIREMENTS: This program is a letter guessing game where a simple Al opponent generates a secret letter for the user to guess. The user must be able to take turns guessing the secret letter, with the Al responding to the user's guesses. After successfully guessing, the user must be allowed to play again. The Al must count how many turns the user has taken. Here is an example of a game in progress where the human user...

  • I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm...

    I need help with this assignment. Please include comments throughout the program. Thanks Develop an algorithm and write the program in java for a simple game of guessing at a secret five-digit code. When the user enters a guess at the code, the program returns two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 13720, and the user guesses 83521, the...

  • (c++) Write a program that generates a random number between 1 and 100 and asks the...

    (c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT