1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Leona [35]
3 years ago
13

Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number bet

ween 1 and 100 (inclusive), then repeatedly prompt the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or chooses to quit. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop.
Computers and Technology
1 answer:
AnnyKZ [126]3 years ago
7 0

Answer:

import java.util.Scanner;

import java.util.Random;

public class Hi_Lo {

// Create a scanner object to read from the keyboard

static Scanner kb = new Scanner(System.in);

// Create a Random object to be used to generate random numbers

static Random rand = new Random();

// This is the main method

public static void main(String[] args) {

 // Call the playGame() method

 playGame();

}

public static void playGame() {

 // Generate a random number between 1 and 100 both inclusive

 // Store the value in an int variable, num

 int num = rand.nextInt(100) + 1;

 // Create and initialize a variable to hold the user's guess

 int guess = 0;

 // Create and initialize a variable to hold the number of guesses

 int guesses = 0;

 // Create an infinite do while loop that keeps looping until a certain condition

 // is reached.

 do {

  // Prompt the user to enter a number between 1-100

  System.out.println("Guess what number I have (1-100)? ");

  // Store the user input in the guess variable

  guess = kb.nextInt();

  // Increment guess by one

  guesses++;

  // Check if the user's guess (guess) is greater than, less than or equal to the

  // generated random number (num).

  // If it is greater or lower, ask the user to try again.

  // If they are equal, display how many times they guessed and ask if they want

  // to play again.

  if (guess > num) {

   System.out.println("Too high, try again.");

  } else if (guess < num) {

   System.out.println("Too low, try again.");

  } else {

   System.out.println("You're right, the number is " + num);

   System.out.println("You guessed " + guesses + " times");

   // Ask the user if they want to play again

   // If yes, recursively call the playGame method again

   // Otherwise, break out of the loop.

   // Make sure the user's input is treated as case insensitive by using the

   // equalsIgnoreCase method.

   // The user can type yes, no, y or n. Case does not matter.

   System.out.println("Do you want to play again? (Y or N)");

   String answer = kb.next();

   if (answer.equalsIgnoreCase("Yes") || answer.equalsIgnoreCase("Y")) {

    playGame();

   } else {

    System.out.println("Game aborted. Thanks for your time");

    break;

   }

  }

 } while (true);

}

}

Answer has also been attached to this response as a source code file. Please download the file for more readability.

Explanation:

The code contains comments explaining every segment of the code. Kindly download the file and go through the comments in the code.

Hope this helps!

Download java
You might be interested in
Question 16 of 40
neonofarm [45]

Answer:

D hjjhhhhhhhhhhhhhhh

Explanation:

cuz

6 0
3 years ago
Read 2 more answers
What coding language should i begin with if i'm looking to get into AI ?
loris [4]

Depends really. Have you got prior coding experience? The semantics of certain languages are much easier to pick up if you've had prior experience, but it might seem impossible to someone who has minimal experience.

Assuming that you're no older than 15 or 16, I'm going to suggest Python. It's a simple, high-level language that's easier to understand than most languages. If you think you've got enough experience to quickly understand and pick up things, then I'd probably say R is a good language to start with. It's very well-suited for AI and tends to be a favourite for AI researchers.

7 0
3 years ago
maximum cardinality indicates whether or not an instance of one entity class must be related to at least one instance of another
vladimir1956 [14]

This is false.

What is cardinality?

Cardinality refers to the entity instances for which it is eligible to participate in a relationship instance. There are two types of cardinality, maximum and minimum.

What is maximum cardinality?

  • The maximum cardinality of a relationship is the maximum number of instances of entity B that may be associated with each instance of entity A.
  • Maximum cardinality: maximum number of entity instances that can participate in a relationship.
  1. One-to-One [1:1]
  2. One-to-Many [1:N]
  3. Many-to-Many [N:M]

To know more about maximum cardinality , refer:

brainly.com/question/18090451

#SPJ4

4 0
1 year ago
What could be the reasons of Blue Screen of Death on Windows computers?
muminat

Answer:

The reasons for  Blue Screen Of Death are as following:-

  1. Faulty Memory.
  2. Power Supply Issue.
  3. Overheating of Components.
  4. Malfunctioning Hardwares.
  5. Poorly coded device drivers.
  6. Hardware runnign beyond it's capacity.
  7. Bugs in the Operating System Kernel.

These are the some of the reasons why the blue screen of death is caused.

6 0
3 years ago
Which of the following is a geolocation service on an Internet browser?
seropon [69]
It may be D) because it is actually a simplified version of Google maps.
7 0
3 years ago
Read 2 more answers
Other questions:
  • When it comes to saving money, what is a good rule of thumb?
    5·2 answers
  • ​What file system below does not support encryption, file based compression, and disk quotas, but does support extremely large v
    10·1 answer
  • Where can the Ease of Access and Speech Recognition centers be found?
    8·2 answers
  • Computers store temporary Internet files in the Recycle Bin. These files take up space and slow down a computer. Which tool can
    10·1 answer
  • Why is charles babbage known as father of computer?​
    10·1 answer
  • Which of the following is a key feature of SmoothWall? Weak traffic graphs and bandwidth bars Universal Plug and Play support DM
    7·1 answer
  • What is a conditional Statement that causes the program to change its course​
    11·1 answer
  • 4
    15·2 answers
  • What is the missing part to have the output as 3 2 1 while count &gt;0 : print(count) count -= 1
    10·1 answer
  • besides entering a url to go directly to a website, what else can you enter in a browser address bar to explore the internet?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!