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
How do I type the integral symbol?
vredina [299]
<span><span>Alt 244 =⌠
</span><span>
Alt 245 =<span>⌡

So, you're going to hit "Alt", then over to the side of your keyboard, you should see groups of numbers. Not the numbers above your letters, but the ones on to the side. While pressing "Alt", you're going to hit either 244, or 245. 

I hope I helped :)</span></span></span>
3 0
3 years ago
The Spanning Tree Protocol operates at the Network layer of the OSI model.
BigorU [14]

Answer:

False

Explanation:

The Spanning Tree Protocol operates at the Data link layer of the OSI model.

Spanning Tree Protocol (STP) is a bridge and switch (Layer 2 protocol). The STP specification is IEEE 802.1D. STP's primary aim is to guarantee that when you have redundant routes in your network, you do not generate loops. Loops to a network are fatal.

6 0
3 years ago
Explain the components of Information System?​
slavikrds [6]

Answer:

An information system is essentially made up of five components hardware, software, database, network and people. These five components integrate to perform input, process, output, feedback and control. Hardware consists of input/output device, processor, operating system and media devices.

Explanation:

7 0
3 years ago
What are the 6 external parts of a computer system
denis23 [38]
1. Monitor
2.C.P.U
3.Mouse
4. Keyboard
5. Printer
6. Speaker
4 0
3 years ago
As part of a team, you are assigned to create a financial report. One of your tasks is to put the pieces together as other team
erastova [34]
Summary task
or
Introduction
6 0
3 years ago
Other questions:
  • Windows uses a graphical user interface (GUI), which means: a user can carry out commands by clicking, dragging, or otherwise ma
    6·1 answer
  • A defined set of standards that computers must follow in order to communicate properly is known as a
    13·2 answers
  • How many times do you usually use npm?<br> Put your answer in the box.
    6·1 answer
  • What is the first step to creating a PivotTable?
    11·1 answer
  • To close the ____ view, click File on the Ribbon or click the preview of the document in the Info gallery to return to the docum
    9·1 answer
  • What are the characteristics of good blogs?
    8·1 answer
  • Tennis players are not allowed to swear when they are playing in Wimbledon
    6·2 answers
  • In the computer science industry, the process of finding and removing errors from computer hardware or software is known as
    7·1 answer
  • Compare mini and mainframe computer in terms of speed,memory and storage​
    15·1 answer
  • What is draft pls help me​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!