Please use Java.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Please use Java.

Post by answerhappygod »

Please Use Java 1
Please Use Java 1 (84.08 KiB) Viewed 42 times
Please use Java.
Question 1 (10 marks) Write a program for guessing a number. The computer generates a random integer between 1 and 10, inclusively. The user guesses the number value with at most three tries. If the user gives the correct integer, the game terminates immediately. Otherwise, when the user has not used up the tries, the program shows a hint that narrows down the range of the integer after each guess. Assume the current range is lower to upper and the user takes a guess of x between lower and upper. If x is less than the correct number, the program narrows down the range to x + 1 to upper. If x is greater than the correct number, the program narrows down the range to lower to x-1. if x is outside the range of lower to upper, the program shows the range of lower to upper. When the user has used up the tries but still did not get the number, the program displays the number with some message and terminates the game. Requirement: • No error checking is needed. You can assume that the users always enter valid input data. Example 1 (The data underlined is entered by users) I am thinking of a number between 1 and 10. Can you guess what it is? 5 The number is between 6 and 10. Try again: 8 Congratulations! You did it. The number was 8. Example 2 (The data underlined is entered by users) I am thinking of a number between 1 and 10. Can you guess what it is? 7 The number is between 1 and 6. Try again: 3 The number is between 4 and 6. Try again: 5 Sorry. The number was 4. Better luck next time
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply