JAVA Programming Revisit previous number guessing game in which the user picks a number from 1 to 100 and your program tries to guess the number. Sample runs of the program for refresher:  - https://www.youtube.com/watch?v=ypZUZ3sBfaI Creating the NumberGuesser class Write your NumberGuesser class as if it is going to be used in many different guessing games, created by different developers. You want to create a class that will be a useful tool in different contexts.  When a new instance of a NumberGuesser class is instantiated the upper and lower bounds of the possible values should be passed into its constructor.  From that point on a NumberGuesser object will always return the midpoint of the possible values when the getCurrentGuess() method is called. If the higher() or lower() methods are invoked, the NumberGuesser object should adjust its state to represent the new possible range of values. For example, if a NumberGuesser is created with the following line of code then the range will be the numbers from 1 to 100: NumberGuesser guesser = new NumberGuesser(1, 100); If the getCurrentGuess() method is called it should return 50, which is the midpoint between 1 and 100.  If the higher() method is invoked then the object should adjust its state accordingly so that it knows that the correct value is between 51 and 100.  If the lower() method is invoked then it should adjust its state to represent that the possible values are between 1 and 49. After that, the getCurrentGuess() should return the value that is in the middle of the new range of possible values. (Either 75 or 25).  By following this strategy the number guesser should be able to eventually guess the proper value. Here is the basic design of the NumberGuesser class that you should write. The instance variables have been left up to you. NumberGuesser Class Private Member Fields ?? Public Methods and Constructors NumberGuesser(int lowerBound, int upperBound) void higher(); void lower(); int getCurrentGuess(); void reset();   The reset() method should return the NumberGuesser to the state that it was in when it was constructed.  In order to do this your class will need to be able to remember its original state. You can use two additional instance variables to store the original upper and lower bounds. You might not need to invoke this method in your game for this project, but you will need to in later projects. Write your number guess class and test it until you are sure that it is working properly. After it is working, write the rest of the program so that it plays the game by using an instance of your NumberGuesser class. Note: Your NumberGuesser class should not use a Scanner object or System.out. It is only responsible for handling the indicated methods. All of the input and output work should be handled elsewhere in your program.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter2: Elements Of High-quality Programs
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

JAVA Programming

Revisit previous number guessing game in which the user picks a number from 1 to 100 and your program tries to guess the number. Sample runs of the program for refresher:  - https://www.youtube.com/watch?v=ypZUZ3sBfaI

Creating the NumberGuesser class

Write your NumberGuesser class as if it is going to be used in many different guessing games, created by different developers. You want to create a class that will be a useful tool in different contexts. 

When a new instance of a NumberGuesser class is instantiated the upper and lower bounds of the possible values should be passed into its constructor.  From that point on a NumberGuesser object will always return the midpoint of the possible values when the getCurrentGuess() method is called.

If the higher() or lower() methods are invoked, the NumberGuesser object should adjust its state to represent the new possible range of values. For example, if a NumberGuesser is created with the following line of code then the range will be the numbers from 1 to 100:

NumberGuesser guesser = new NumberGuesser(1, 100);

If the getCurrentGuess() method is called it should return 50, which is the midpoint between 1 and 100.  If the higher() method is invoked then the object should adjust its state accordingly so that it knows that the correct value is between 51 and 100.  If the lower() method is invoked then it should adjust its state to represent that the possible values are between 1 and 49.

After that, the getCurrentGuess() should return the value that is in the middle of the new range of possible values. (Either 75 or 25).  By following this strategy the number guesser should be able to eventually guess the proper value.

Here is the basic design of the NumberGuesser class that you should write. The instance variables have been left up to you.

NumberGuesser Class

Private Member Fields

??

Public Methods and Constructors

NumberGuesser(int lowerBound, int upperBound)

void higher();

void lower();

int getCurrentGuess();

void reset();

 

The reset() method should return the NumberGuesser to the state that it was in when it was constructed.  In order to do this your class will need to be able to remember its original state. You can use two additional instance variables to store the original upper and lower bounds. You might not need to invoke this method in your game for this project, but you will need to in later projects.

Write your number guess class and test it until you are sure that it is working properly. After it is working, write the rest of the program so that it plays the game by using an instance of your NumberGuesser class.

Note: Your NumberGuesser class should not use a Scanner object or System.out. It is only responsible for handling the indicated methods. All of the input and output work should be handled elsewhere in your program.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,