Question

For this lab you will write a Java program using a loop that will play a simple Guess The Number game. Th gener e program will randomly loop where it prompt the user for a ate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a r has guessed the correct number, the program will end with a message indicating how many guesses it took to get the right answer and a incorrectly, the program should respond with a message that th again. message that is determined by how many guesses it takes them to get the right answer. If the user guesses e user has guessed either too high or too low and let them guess Use the following table to determine the final message after the messages to be considered correct) Message That was astounding That was lucky! That was pretty good. That was not that impressive. Are you sure this is the right game for you? This just isnt your game, is it? 2-4 5-6 8-9 10 or more
media%2Fc86%2Fc8618f34-568f-42b5-9a99-31
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

import java.lang.*;

public class numberGuess {

public static void main(String[] args) {

int max = 200, min = 1;

int range = (max - min) + 1;

int x = (int)(Math.random() * range) + min;

int tries = 0, guess;

System.out.println("Guess a guess between 1 and 200 : ");

Scanner input = new Scanner(System.in);

do{

guess = input.nextInt();

if (guess < 1 || guess > 200){

System.out.println("That is not a valid entry. Please try again: ");

}else if (guess > x){

System.out.println("Your guess was too high. Try again.");

}else if (guess < x){

System.out.println("Your guess was too low. Try again.");

}

tries++;

} while (guess != x);

System.out.println("Congratulations! Your guess was correct!");

System.out.println("I had chosen " + guess + " as the target number.");

System.out.println("You guessed it in " + tries + " tries.");

if(tries == 1)

System.out.println("That was astounding!");

else if(tries>=2 && tries<=4)

System.out.println("That was lucky!");

else if(tries>=5 && tries<=6)

System.out.println("That was pretty good.");

else if(tries == 7)

System.out.println("That was not that impressive.");

else if(tries>=8 && tries<=9)

System.out.println("Are you sure this is the right game for you?");

else if(tries>=10)

System.out.println("This just isn't your game, is it?");

}

}

Add a comment
Know the answer?
Add Answer to:
For this lab you will write a Java program using a loop that will play a...
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
  • Write a program to play "guess my number". The program should generate a random number between...

    Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...

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

  • IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one...

    IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one and 100. Then it will ask the user to make a guess as to what the number is. If the guess is incorrect, but is within the range of 1 to 100, the user will be told if it is higher or lower and then asked to guess again. If the guess was outside the valid range or not readable by Scanner class, a...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • Can someone upload a picture of the code in matlab Write a "Guess My Number Game"...

    Can someone upload a picture of the code in matlab Write a "Guess My Number Game" program. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: 1. The program starts by printing instructions on the...

  • Write a Java Program to allow a user to guess a person’s age until they get...

    Write a Java Program to allow a user to guess a person’s age until they get it correct. After each guess, the user must be told whether their guess was correct, too high or too low. Once the user enters the correct age, the program must display how many guesses it took the user to guess the correct age.

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

  • Code in JAVA.................... Guess the Number In this activity, you will write a REST server to...

    Code in JAVA.................... Guess the Number In this activity, you will write a REST server to facilitate playing a number guessing game known as "Bulls and Cows". In each game, a 4-digit number is generated where every digit is different. For each round, the user guesses a number and is told the exact and partial digit matches. An exact match occurs when the user guesses the correct digit in the correct position. A partial match occurs when the user guesses...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle 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