Question

In: Computer Science

We will create a program that will guess a number between 1 and 100 chosen by...

We will create a program that will guess a number between 1 and 100 chosen by the user.Your program will be iteratively built in several stages, where each stage focuses on implementing just one type of operation. Each stage will build upon the work from the previous stage. This is known as iterative design, a process that allows us to focus on working on a single, simple task at a time, but the resulting software slowly evolves into something much more complex.

Required Concepts: The final homework requires that you implement the following concepts: 1. Storage operations (store data in program) 2. Output operations (print data to screen) 3. Input operations (get data from user) 4. Selection operations (multiple selection based on player input) 5. Mathematical operations (arithmetic, equality, relational) 6. Repetition operations (loop game logic to model multiple turns) 7. Nested selection operations (validate that user’s selection meets rules requirements) CODE IN JAVA!!

Solutions

Expert Solution

import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       Random r = new Random();
       //generating random number
       int rand = r.nextInt(100);
       System.out.println("Ranom number generated from 1-100");
       int count = 0;
       while (true) {

           System.out.println("Enter your guess");
           // taking number from user
           int num = sc.nextInt();
           //validating if the given number is in range
           if (num < 0 || num > 100) {
               System.out.println("Number must be between 1-100");
               continue;
           }
           //checking if both are equal
           if (num == rand) {
               System.out.println("Good guess");
               break;
           } else if (num < rand) {
               System.out.println("Low.. try again");
           } else {
               System.out.println("High.. try again");

           }
       }
       sc.close();
   }
}

Note : If you like my answer please rate and help me it is very Imp for me


Related Solutions

Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i used random.randint(1,1000) -must give hints like (pick a lower/higher number) which i already did -tell the user when he has repeated a number (help) -the game only ends when you guess the number (help) -you loose $50 every failed attempt (done) ****I did it as a while loop -
Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...
Project 5-3: Guessing Game Create an application that lets a user guess a number between 1...
Project 5-3: Guessing Game Create an application that lets a user guess a number between 1 and 100. Console Welcome to the Guess the Number Game ++++++++++++++++++++++++++++++++++++ I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 You got it in 1 tries. Great work! You are a mathematical wizard. Try again? (y/n): y I'm thinking of a number from 1 to 100. Try to guess it. Enter number: 50 Way too high! Guess...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails. Use a random generator to get random guesses every time. If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.   If the user does not guess correctly, subtract a point. Create a menu that allows the user to continue guessing, view the current score...
1. [100] Create a C program for a number guessing game. Here are the requirements: a....
1. [100] Create a C program for a number guessing game. Here are the requirements: a. Your program generates a random number between -100 and 100 and keeps asking the user to guess the number until the user guesses it correctly. Your random number generator should be implemented as a C function which takes min and max values as input parameters and returns a random number between those values including the min and the max. b. If the user guesses...
Create a C++ program that generates a random number from 1 to 100 using the rand()...
Create a C++ program that generates a random number from 1 to 100 using the rand() function. Give the user a total 5 chances to guess the number. Stop the program and indicate the user guessed the correct number and should be applauded. Also, please find out which guess was the closest to the actual number. For example, if the rand() produces 57 and the user guessed 10, 80, 52, 33 and 44 in their respective turns then print out...
Write a program that generates a random number between 1 and 100 and asks the user...
Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Your program should also keep a...
A number between 1 and 10 is chosen at random . What is the probability of...
A number between 1 and 10 is chosen at random . What is the probability of getting a multiple of 5 or an even number?
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT