Question
Write a subclass of the NumberGuesser class named RandomNumberGuesser . The subclass should change the behavior of the getCurrentGuess method. In the current NumberGuesser class
Write a subclass of the NumberGuesser class named RandomNumberGuesser. The subclass should change the behavior of the getCurrentGuess method.
In the current NumberGuesser class the getCurrentGuess method returns the midpoint of the range of possible values. In the RandomNumberGuesser class the getCurrentGuess should return a randomly generated number in the range of possible values.
Note that repeated calls to getCurrentGuess() should always return the same value for both classes if neither the higher() or the lower() methods are called. Consider the following example:
NumberGuesser ng = new NumberGuesser(1, 10);
System.out.println(ng.getCurrentGuess());
System.out.println(ng.getCurrentGuess());
System.out.println(ng.getCurrentGuess());
Each invocation of getCurrentGuess should return 5. The value should not change until the higher() or lower() method is invoked.
Now consider a RandomNumberGuesser example:
RandomNumberGuesser rng = new RandomNumberGuesser(1, 10);
System.out.println(rng.getCurrentGuess());
System.out.println(rng.getCurrentGuess());
System.out.println(rng.getCurrentGuess());
The first invocation of getCurrentGuess() should return a random number between 1 and 10. Each subsequent call should return the same number, until higher() or lower() is invoked.
You can modify your NumberGuesser to make it a better class for subclassing. You might want to make instance variables or methods protected instead of private. So long as your NumberGuesser class still works as originally described any changes are fine.
What to Submit
Submit a zip file that contains your NumberGuesser.java file, and RandomNumberGuesser.java file, and a working guessing game that uses the RandomNumberGuesser.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started