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

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

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

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

  • The game must be done in java in Netbeans 1. Write a Guessing Game. In the...

    The game must be done in java in Netbeans 1. Write a Guessing Game. In the game, the user will guess a number. a. In the StartGui, the use needs to choose a difficulty level: Easy or Difficult. If easy level is selected, the user will guess between 1 and 10. If difficult level is selected, the user will guess 1 and 100. Then the user will click Start button and go to the GamePage. b. In the GamPage, the...

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