Question

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 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================

import java.util.Scanner;

public class GuessingGame {


    public static void main(String[] args) {


        Scanner keyboard = new Scanner(System.in);

        System.out.print("Pick a number from 1 to 10. When ready hit a key");
        keyboard.nextLine();

        System.out.print("Is your number a divisible by 2 (Yes or No): ");
        String yesOrNo = keyboard.nextLine();
        if (yesOrNo.equalsIgnoreCase("yes")) {

            System.out.print("Is your number greater than by 5 (Yes or No): ");
            String greater = keyboard.nextLine();
            if (greater.equalsIgnoreCase("yes")) {
                System.out.print("Is you number greater than or equal to 8 (Yes or No): ");
                String eight = keyboard.nextLine();
                if (eight.equalsIgnoreCase("Yes")) {
                    System.out.print("Is your number divisible by 5 (Yes or No): ");
                    String ten = keyboard.nextLine();
                    if (ten.equalsIgnoreCase("Yes")) System.out.println("Your number is 10");
                    else System.out.println("Your number is 8");
                } else {
                    System.out.println("Your number is 6");
                }

            } else {
                System.out.println("Is your number divisible by 4 (Yes or No): ");
                String four = keyboard.nextLine();
                if (four.equalsIgnoreCase("yes")) System.out.println("Your number is 4");
                else System.out.println("Your number is 2");
            }

        } else {

            System.out.print("Is your number greater than or equal to 5 (Yes or No): ");
            String greaterThanFive = keyboard.nextLine();
            if (greaterThanFive.equals("yes")) {
                System.out.print("Is your number divisible by 3 (Yes or No): ");
                String nine = keyboard.nextLine();
                if (nine.equalsIgnoreCase("yes")) {
                    System.out.println("Your number is 9");
                } else {
                    System.out.print("Is your number divisible by 5 (Yes or No): ");
                    String five = keyboard.nextLine();
                    if (five.equalsIgnoreCase("yes"))
                        System.out.println("Your number is 5");
                    else
                        System.out.println("Your number is 7");
                }
            } else {

                System.out.print("Is your number divisible by 3 (Yes or No): ");
                String three = keyboard.nextLine();
                if (three.equalsIgnoreCase("yes"))
                    System.out.println("Your number is 3");
                else
                    System.out.println("Your number is 1");
            }
        }


    }
}
===============================================================================

Sample Run for a number 5

Thanks, let me know for any questions or in case you encounter any issue.

Please do give a thumbs up from your end : )

Add a comment
Know the answer?
Add Answer to:
JAVA PROGRAM: Guessing Game Objective The student will write an individualized program that utilizes conditional flow...
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
  • 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....

  • 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...

  • 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...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • Write a Java program that implements the number guessing game where the computer tries to guess...

    Write a Java program that implements the number guessing game where the computer tries to guess a number in your head. You pick a number between 0 and 100, and the computer generates a guess. You then type 1 if your number is larger than the computer’s guess, -1 if your number is smaller, and 0 if the number is correct. The computer should keep trying to guess the number by adjusting the guess based on your feedback (so if...

  • Java Guessing Game Class The class will generate a random number of 1 to 15, and...

    Java Guessing Game Class The class will generate a random number of 1 to 15, and then check to see if the user guessed the number correctly. If the number is incorrect, the user should have the chance to guess again, until they guess the right number or they guess 10 times. The class method should keep track of the number of guesses the user has had, and return this value.   The class should have one constructors, a default and...

  • 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...

  • 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...

  • Required in JAVA language Write a program that enables a user to play number guessing games....

    Required in JAVA language Write a program that enables a user to play number guessing games. The following is a nutshell description of a number guessing game. + a random number is generated + loop prompting the user to enter guesses until the user guesses the number or hits the maximum number of allowed guesses or enters the "quit" sentinel value The rest of this specification documents number guessing games in more detail. The documentation uses manifest constants that can...

  • Number Guessing Game Games Write program in C++. For this game, the computer will select a...

    Number Guessing Game Games Write program in C++. For this game, the computer will select a random number between 1 and 100 (inclusive). The computer will then ask the (human) player to guess the number the computer has selected. After the player’s guess is input to the computer, the computer will output one of three responses, depending on the relationship of the number the player guessed to the number the computer selected: “Your guess was too low.” “Your guess was...

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