Question

In: Computer Science

The goal of the game (program) is let a user input a random number in the...

The goal of the game (program) is let a user input a random number in the range of 0-10, and then give the user feedback as to whether this number is the same, bigger or smaller than the one the computer generated.

Given this, the second task is to refine the program we just created so that the program compares the user's input with the secret number to

  1. If the user's input is equal to the number, print out the message " The input number is correct"
  2. If the user's input is larger, print out the message "The input number is too large",
  3. If the user's input is smaller, print out the message "The input number is too small"

HINT: You need functions seven from the sample code (see previous activity).

Steps

Please download this sample code, using Netbeans revise it to satisfy the above requirements. Please submit a print screen of your successful code including the Output window with the "Build Successful" message to this assignment.

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates * and open the template in the editor.

*/// We need to import the following library to display the message dialog window.// import javax.swing.JOptionPane;/*

* This is a list of functions we need to use.

* 1. Create an integer variable:* int integerName = 0;

* 2. Collect user input from a dialog:* String userInput = JOptionPane.showInputDialog("your message");

* 3. Print out a message using a message dialog: * JOptionPane.showMessageDialog(null, "your message", "title of the dialog", JOptionPane.PLAIN_MESSAGE);

** 4. When we use the dialog message, at the very end, we need to add one line of code:* System.exit(0);

* 5. Convert a string to an integer* int intNum = Integer.parseInt(stringVariable);

* 6. Generate a random integer in the range of [minimum, maximum]* int random = minimum + (int) (Math.random() * maximum);

* 7. Decision Structure* if(condition) {* your instructions ...* } else {* your instructions ...* }*

* 8. Loop Structure* while (condition) {* your instructions ...* }**/

package numberguessgame;import javax.swing.JOptionPane;public class NumberGuessGame { /** * @param args the command line arguments */ public static void main(String[] args) { int integername = 0; int minimum = 0; int maximum = 10; String userInput = JOptionPane.showInputDialog("Guess a number between 0 and 10"); /*System.out.println(userInput);*/ int intNum = Integer.parseInt(userInput); JOptionPane.showMessageDialog(null, intNum, "Your guess",

JOptionPane.PLAIN_MESSAGE); int random = minimum + (int) (Math.random() * maximum); /*System.out.println(random);*/ JOptionPane.showMessageDialog (null, random, "The correct number", JOptionPane.PLAIN_MESSAGE); }}

Solutions

Expert Solution

JAVA program for the provided problem statement

Program Output


Related Solutions

Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random...
Program Created Last Week: #Program plays a guessing the number game with the user. #Importing random number with min number being 1 and max being 10 import random min_number = 1 max_number = 10 rand = random.randint(min_number, max_number) #Prints the header, welcoming the user print("Welcome to the Guess My Number Program!") while (True): #While loop, comparing the users guessed number with the random number. #If it matches, it will say you guessed it. guess = eval(input("Please try to guess my...
C++ The program implements the Number Guessing Game. However, in that program, the user is given...
C++ The program implements the Number Guessing Game. However, in that program, the user is given as many tries as needed to guess the correct number. Rewrite the program so that the user has no more than five tries to guess the correct number. Your program should print an appropriate message, such as “You win!” or “You lose!”.
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Random Number Guessing Game Write a program in C++ that generates a random number between 1...
Random Number Guessing Game Write a program in C++ 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....
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 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 while keeping a count of the number of guesses...
guessing game in Java. It will have a guess input used for guessing the random number...
guessing game in Java. It will have a guess input used for guessing the random number that is generated from 1 - 100. When the user makes a guess it will tell them if the number is lower or higher than the guess. There is also a choice to give up which then reveals the correct number. The last choice will be new game which resets the random number. Last, the program should keep counts of tries. When the user...
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number...
Random Number Guessing Game (python) *use comments Write a program guess.py that generates a random number in the range of 1 through 20, 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." If the user guesses the number, the application should congratulate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT