Question: 1) (10pts.) - In this assignment, you will be responsible for creating a random number guessing game with a twist. Rather than the computer generating

1) (10pts.) - In this assignment, you will be responsible for creating a random number guessing game with a twist. Rather

than the computer generating and hiding a number from the player (as is typical), the player will instead choose a

number which the computer will attempt to guess. Using prompts that inform the computer whether its guesses are too

high or too low (or that it needs to guess higher or lower), your program should intelligently adjust its guessing range to

narrow in on a solution. The program should:

I) Generate a random number guess within a valid range (this range to be either user specified or hard-coded).

If hard-coded, the range should be controlled by a variable or two that can be altered to change the

game's range.

II) Receive user input regarding how the guessed number relates to the player-held number.

"h" is customary for "high"

"l" is customary for "low"

"c" is customary for "correct"

Other inputs may be used at your discretion, but be sure to comment your code appropriately.

III) Use the player response to generate a guess within a better range than its previous guess.

IV) End the game when informed that it has reached the correct number.

V) Prompt the user to play again or not and respond appropriately to this input.

2) (3 pts.) - You should use at least two static variables to store the lowest and highest bounds that the computer can

guess between.

3) (2 pts.) - The program should utilize only the first letter of the user response when requesting another game. "Y",

"Yes", "Yeah", "Yo", "yorangutan", and similar should all result in a new game, while "N", "Nyet", "Never!", "Not again",

"nooooooooo", and similar should result in program termination.

4) (3 pts.) - Your code should include consistent indentation and functions should be limited to those presented in

chapters 1 to 5 of the textbook.

5) (2 pts. ) - Include appropriate program documentation and formatting including:

1) Your first and last name

2) Your contact information

----------------------- Page 2-----------------------

3) Your student ID number

4) The date

5) A short description of the programs function

6) Comments necessary to explain the operation of your program

7) Proper indentation

6) Save your file as GuessingGame.java and upload to Canvas.

A sample log of execution is as follows (user inputs in bold and underlined):

Player is thinking of a number between 1 and 100.

Computer guesses: 60

Player responds, this is (high, low, correct): high

Computer guesses: 25

Player responds, this is (high, low, correct): high

Computer guesses: 10

Player responds, this is (high, low, correct): low

Computer guesses: 18

Player responds, this is (high, low, correct): correct

Computer says: Good game, Dave!

Play again? Yes

Player is thinking of a number between 1 and 100.

[]

Play again? Not right now

Thanks for playing!

Optional criteria:

1) Can you ensure that the computer will not guess the same number twice per session?

2) Can your program identify erroneous responses (ie. if the players states both that 10 is too high and 11 is too low)?

3) Add a counter to your program to track the number of turns that have been made.

4) Can you add a function that self-reports whether the guess was low or high, thus removing the human player?

5) Just food for thought, can you imagine what the ideal "guess" pattern might look like? What would be about the

maximum number of turns it should ideally take to find an integer between 1 and 1,000,000,000?

----------------------- Page 3-----------------------

Tips:

- String class methods from section 3.3 and 4.1 may be used to parse user inputs.

- The next() method of the Scanner class may be used to read a word from the console. Be sure to import java.util.*.

- The chapter 5 case study will be of particular relevance to this assignment.

- If the computer is informed that its guess was incorrect, ideally the guessed value should not be within the next range.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!