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
Dione has created a PowerPoint presentation that has several common nouns, names of products, etc. He is
svetlana [45]

Answer:

D. Add

Explanation:

PowerPoint application can be defined as a software application or program designed and developed by Microsoft, to avail users the ability to create various slides containing textual and multimedia informations that can be used during a presentation. Some of the features available on Microsoft PowerPoint are narrations, transition effects, custom slideshows, animation effects, formatting options etc.

In this scenario, Dione has created a PowerPoint presentation that has several common nouns, names of products, etc. He is running Spell Checker and does not want to be notified in regard to these words in this presentation or in any other presentation created on this computer. Hence, the option he should choose is Add. This would be used to automatically add a list of all the common nouns.

3 0
2 years ago
Read 2 more answers
The devices and methods that enable physically challenged computer uses to control their computer and provide input are referred
Minchanka [31]

Answer:

Assistive technologies

Explanation:

Assistive technologies are adaptive devices and softwares that are designed to serve as aids to people with disabilities in improving their functional capabilities and making them carry out activities that are difficult to perform independently. Assistive technologies include devices and software programs that are designed for physically challenged people to help them improve their use of their computer. Examples include JAWS, Voiceover which are screen reader softwares designed for the visually impaired people.

8 0
3 years ago
_____ is the operation of setting a variable to a value.
Helen [10]

Answer:

Assignment is the operation of a variable to a value

3 0
3 years ago
In asps, the code to tie the database to the web site is typically written in javascript or ____.
Dominik [7]
In asps, the code to tie the database to the web site is typically written in javascript or VBScript<span>(Visual Basic Script).
</span>VBScript is an interpreted script language from Microsoft<span> with syntax very similar to that of Visual Basic.
</span><span>Most often VBScript is used for Quick Test Professional (QTP), which is a test automation tool.</span>
4 0
3 years ago
Create a program to deteate a program to determine whether a user-specified altitude [meters] is in the troposphere, lower strat
nordsb [41]

Answer:

#include <iostream>

using namespace std;

int main()

{

   float altitude;

   cout<<"Enter alttitude in meter";

cin >>altitude;

if(altitude<0 || altitude > 50000)

{

   cout<<"Invalid value entered";

   return 0;

}

else{

   if(altitude<= 10000)

   {cout <<"In troposphere "<<endl;}

   

   else if(altitude>10000 && altitude<=30000)

   {cout <<"In lower stratosphere"<<endl;}

   

   else if(altitude>30000 && altitude<=50000)

   {cout <<"In upper stratosphere"<<endl;}

   

}

   return 0;

}

Explanation:

Define a float type variable. Ask user to enter altitude in meters. Store value to altitude variable.

Now check if value entered is positive and less than 5000,if its not in the range of 0-50,000 display a termination message and exit else check if it's in less than 10000, in between 10000 and 30000 or in between 30000 and 50000.

10,000 is above sea level is troposphere.

10,000-30,000 is lower stratosphere.

30,000-50,000 is upper stratosphere.

3 0
3 years ago
Other questions:
  • Which task might be suitable for moving into a separate function so you can re-use it from multiple places in your code?
    11·1 answer
  • A Uniform Resource Locator (URL) consists of three separate parts: network protocol, host, and web browser.
    11·2 answers
  • Write a program that utilizes the concept of conditional execution, takes a string as input, and: prints the sentence "Yes - Spa
    8·1 answer
  • 1. What is the main factor that affects Earth’s average temperature?
    12·1 answer
  • Shape is very prominent in the image of the telephone other elements are ( Color, Space, or Line) and (Form, Space, or Texture)
    15·2 answers
  • Write a program that receives an character and displays its Unicode. Here is a sample run: Enter an character: E The Unicode for
    8·1 answer
  • Write a program that estimates how many years, months, weeks, days, and hours have gone by since Jan 1 1970 by calculations with
    15·1 answer
  • Write the Python programs for the
    13·1 answer
  • Select the correct answer.
    6·1 answer
  • 8. Give regular expressions with alphabet {a, b} for
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!