Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3.666666 You MUST add comments all throughout your code to explain what your code is trying to do. Pay close attention to the directions!! Make

3.666666 You MUST add comments all throughout your code to explain what your code is trying to do.

Pay close attention to the directions!! Make absolutely certain that you are doing exactly what the assignment asks you to do. If you don't understand the problem, make sure to ask your instructor or an assistant.

Declare all of your variables at the beginning of the program. Add blank lines between sections of code to space out your program more and make the sections easier to see.

part 3

Create a new Java class inside your project folder. The name of the class should be: NumberGame

Write a java application program that plays a number guessing game with the user.

Your program should begin by choosing a random number between 0 and 99 (inclusive). YOU MUST include the following statements to do this. Insert them into your program EXACTLY as shown below and do not change anything about them! You will not received credit for this problem if the following three lines are not found in your program.

int secret; Random generator = new Random(); secret = generator.nextInt(100);

After executing the above statements, the variable secret will be holding a randomly generated number from 0 to 99. If you need to get another randomly generated number, you just simply repeat the last line again. Do not repeat all three lines.

Next, your program should ask the user to try to guess what number was chosen.

If the user does not guess the number correctly, you should tell the user that the secret number is higher or lower than the one they guessed. At this point you should allow them to guess again.

Repeat this process until the user guesses the number correctly.

Whenever the user does correctly guess the number, you should stop the program and print to the screen the number of tries that it took the user to guess the number. Make sure to use correct grammar when printing your final message to the user (for example "1 guess" or "2 guesses" -- make sure your program doesn't say "1 guesses" or "2 guess").

Notes:

While testing your program, you can simply set secret to a known value, so that you can properly test your program by knowing the correct answer.

For example:

int secret; Random generator = new Random(); secret = generator.nextInt(100); secret = 54;

Here, I have overwritten the random number, of which I don't know the value, with a number - 54 - which I obviously do know the value. The purpose is so I will know the answer to the problem and therefore will know whether or not the program is correctly telling me "higher" or "lower" when I am making my guesses. Obviously, once you know the program works correctly, you will want to take the secret=54 line out so the answer will be random each time the program executes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago