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
Which is an example of a zero-point perspective?
kap26 [50]

i think its b sorry if  wrong

4 0
3 years ago
Describe the type of gameplay seen during early video games (ex. Spacewar!, Pong).
Elina [12.6K]
  • Sandbox. ...
  • Real-time strategy (RTS) ...
  • Shooter (FPS and TPS) ...
  • Multiplayer online battle arena (MOBA) ...
  • Role-playing games (RPG, ARPG, and more) ...
  • Simulation and sports.

<em>-</em><em> </em><em>BRAINLIEST</em><em> answerer</em>

3 0
2 years ago
Read 2 more answers
Write a program that outputs "Hello World!".
tekilochka [14]
Print(“Hello World!”)

I hope this helps :) I’m sry is this what you wanted or were you looking for something else because I’m willing to help either way.
4 0
2 years ago
fill down feature on a formula and you need to keep a cell reference the same which one will allow you to keep the same cell ref
dedylja [7]
A dollar sign after both the letter and the number for each cell reference you want to keep the same will keep it the same when using the fill down/across function.
6 0
3 years ago
This assignment is to code a simple hangman game. The game should choose a random word out of a list of words that are coded int
pshichka [43]

Answer:

Programming language not stated.

I'll use python for this question

Explanation:

import random

# library that we use in order to choose

# on random words from a list of words

words = ['rain, 'computer', 'science', 'program, 'python', 'mathematics', 'player', 'condition','reverse', 'water', 'board', 'geeks','learn','school','days','scholar','collar','flood','house','flies']

# Function will choose one random word from this list of words

word = random.choice(words)

print("Guess the word")

guesses = ''"

# 5 turns

turns = 5

while turns > 0:

# counts the number of times a user fails

failed = 0

# all characters from the input word taking one at a time.

for char in word:

# comparing that character with the character in guesses

if char in guesses:

print(char)

else:

print("_")

# for every failure 1 will be incremented in failure

failed += 1

if failed == 0:

# user will win the game if failure is 0 and 'You Win' will be given as output

print("You Win")

# this print the correct word

print("The word is: ", word)

break

# if user has input the wrong alphabet then it will ask user to enter another alphabet

guess = input("guess a character:")

# every input character will be stored in guesses

guesses += guess

# check input with the character in word

if guess not in word:

turns -= 1

# if the character doesn’t match the word then “Wrong” will be given as output

print("Wrong")

# this will print the number of turns left for the user

print("You have", + turns, 'more guesses')

if turns == 0:

print("You Loose")

7 0
2 years ago
Other questions:
  • You have been asked to create an authentication security plan for your company. Which of the following components would you inco
    14·1 answer
  • HURRYYY A friend of yours has E-mailed their English paper to you so that you can proofread it. Explain the tools you would use
    15·1 answer
  • What OS is most commonly used by businesses? Linux Macintosh Microsoft Windows
    11·1 answer
  • Which of the following parameters should match in order for a pair of routers to form an adjacency when running OSPFv2? (Points
    9·1 answer
  • You want to drive traffic to a new landing page for a campaign, and want a web address that's short, easy to remember, trackable
    7·1 answer
  • Im being timed please help!!
    7·2 answers
  • The Receiver recognizes the sounds the Sender is making and transforms them into words and ideas in his own mind. What is this
    5·1 answer
  • Define the terms network, LAN, WAN, and Internet.
    11·1 answer
  • Desktop computers have a(n) ________ unit, located within the system unit, that plugs into a standard wall outlet, converts AC t
    14·1 answer
  • In the bremmer article, the author states that _________ translates into greater risks.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!