Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Guess number game. Write a program in Java to:
a. Generate a random integer between 1 and 100 (inclusive) and prompt user to guess the number.
b. If the guess is not right, give the user the hint like “higher”, “lower”. Allow the user to retry and input the new guess.
c. Likely you want to use a while loop to support the user’s multiple attempts. Stop the loop when the user guessed the number.
d. Print out the number of attempts for the user for this round of game.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Create a new program called MaxSentinel. Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1 is entered, stop prompting for numbers and display the largest number entered by the user. Submit code. Note: Consider using one of the Math class methods or use if statements.arrow_forwardwrite a c++ program Use a pretest loop to allow the user to enter data until they input 0 for the purchase amount. Do all of your output in main(). Make it look like this. Don’t forget your underlines won’t be immediately underneath. Use methods for the following: getPurchaseAmt() Get the monthly purchase amount from the user. Include an error-trap around this input value so the user will have to enter a positive number (0r 0 to end the loop). Return the purchase amount. displayMenu() Display a menu of the membership types for the user to choose from, as follows: Membership Types: Premium Plus Standard Enter choice (1, 2, or 3): This method only displays. There is nothing to return, so it will be a void method. You will call this method from getType(). getType() Call the displayMenu() method and get the membership type from the user. Include an error-trap around the menu and choice so the program will not continue until the user enters a valid choice. Return the choice.…arrow_forwardIn Java Create a class DoWhileEvent3, write code that ask the user to enter a positive or negative number or 'x' 'X' to quit the program. When out of the loop the sum of all numbers entered is printed. READ THE USER'S input as String an not as integer. Use a do while loop.arrow_forward
- The instructions my prof. wants is this: Write a program that prompts the user for a binary number (from 3 to 8 bits) as a String and converts it to base-10 decimal value. There are several ways to do this in Java but your program must use a for loop and first principles to perform the conversion. Print the base-10 number when the loop ends... He sent me a diagram of the binary scale and i've never seen this scale before so I'm having issues with my program. I CAN'T use array, which is an issue I'm having right now. public static int getDecimal(int binary) { int decimal = 0; int n = 0; while(true) { if(binary == 0) { break; }else { int temp = binary %10; decimal += temp * Math.pow(2, n); binary = binary / 10; n++; } } return decimal; } public static void main(String[] args) { System.out.println("11…arrow_forwardin java Integer valueIn is read from input. Write a while loop that iterates until valueIn is negative. In each iteration: Update integer result as follows: If valueIn is divisible by 5, output "win" and increment result. Otherwise, output "lose" and do not update result. Then, read an integer from input into variable valueIn. End each output with a newline. Click here for exampleEx: If the input is 5 15 11 -5, then the output is: win win lose Result is 2 Note: x % 5 == 0 returns true if x is divisible by 5. import java.util.Scanner; public class ResultCalculator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int valueIn; int result; result = 0; valueIn = scnr.nextInt(); /your code here/ System.out.println("Result is " + result); }}arrow_forwardConsider the following program that contains a nested loop. j = while j> 0 : k = 0 while print("#", k = k + 1 print() j = j - 1 end Complete the program so that it prints the following 6 lines exactly:arrow_forward
- Write a program using while loop and for loops to print first 50 prime numbers in 5 lines, each line containing 10 numbers. 1. Create a program called CountCharacters.java. 2. At the top of your java file add the following documentation comments. Replace the italicized text with the appropriate content. /** @author Your Name CS 110 Section 012 Lab 9 Final Today's Date 3. Import the Scanner class and ask user to enter a line. Implement the while loop so that the user can input any number of lines and one line at a time. To stop entering lines, the user can write "quit. (Hint: Use the string method <str>.equals() in the while condition to stop the while loop OR a break keyword). 4. Implement the for loop inside the while loop to iterate through the line one character at a time to count and output the number of blank spaces, alphabetic characters, digit characters, and other characters in all the lines. You need to use different methods of character class like charAt(), isDigit(),…arrow_forwardWrite a Java program that: Ask user to enter the last two digits of the Student ID number and store it in a variable of type integer; Use a while loop to print all the positive odd numbers smaller than the inputted number. After the while loop, make a for loop to print all the positive even numbers smaller than the inputted Note: Your answer should have the code as text, as well as a screenshot of the code with the output. The inputted number should be the last two digits of your Student ID number. ID is : 190058401arrow_forwardWrite a C++ program using loops for a number guessing game. The program generates and stores a random number and prompts a user to guess the number. If user guess is less than the number, display “Sorry, guess is too low”, if user guess is greater than the number, display “Sorry, guess is too high”. If user guesses the right number, display “Congratulations, you have guessed the number”, and number of users tries to guess a number. The program should keep on taking a user input, until user guesses the number. Sample Output 1 (Number 50): Enter a number to guess: 50 “Congratulations, you have guessed the number” in first try. Sample Output 2 (Number 50): Enter a number to guess: 25 “Sorry, guess is too low” Enter a number to guess: 60 “Sorry, guess is too high” Enter a number to guess: 50 “Congratulations, you have guessed the number in 3 tries”, 2.12.0.0arrow_forward
- Can you please make this in Java?arrow_forwardFor C programming!! Thank u so much! Write a program that will uses a loop to display a table of the Celsius temperatures 0-20, and the Fahrenheit equivalents. To convert temperatures from Celsius to Fahrenheit, you need to use the following formula: Fahrenheit = Celsuis + 32.arrow_forwardPrint "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If userInput is "That darn cat.", then output is:Censored Ex: If userInput is "Dang, that was scary!", then output is:Dang, that was scary! Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education