Build an application that will receive a guess and report if your guess is the random number that was generated. Your application will narrow down the choices according to your previous guesses and continue to prompt you to enter a guess until you guess correctly. Notice that if you divide the choices in half each iteration, you will need at most log2(100) ~ 7 guesses. You will use the utility class RNG.java. Data Element Class – RNG • Provided • This file will generate a random number between 1 and 100 • Note that the method “rand” is a static method, so the java file does not need to be instantiated to use it. Call rand with the following: RNG.rand(100) to generate a random number between 0 and 99. • Thank youStudy this class. You will want to use four methods from this class: rand, resetCount, getCount and inputValidation. Driver Class – RandomNumberGuesser • Student created. • This is the driver class for RNG that contains a main method. • The driver is responsible to: o print a header. o ask the user for an initial guess of the Random Number between 0 and 100. o Print out the result for that guess using the methods from the RNG class. o Allow user to give another guess between the previous low and high guesses. o Display the number of guesses. o When user guesses correctly, ask if the user wants to try another round. o Print the Programmer's name at the end. o Refer to the program sample run for more clarification. • Data Validation. The following data is validated by the RNG method inputValidation: o Guesses must be an integer between the previous low guess and high guess. • Naming. o There should be an attribute named randNum. o There should be attributes named nextGuess, highGuess, and lowGuess. • Add any necessary methods to modularize your code

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question
Build an application that will receive a guess and report if your guess is the random number that was generated. Your application will narrow down the choices according to your previous guesses and continue to prompt you to enter a guess until you guess correctly. Notice that if you divide the choices in half each iteration, you will need at most log2(100) ~ 7 guesses. You will use the utility class RNG.java. Data Element Class – RNG • Provided • This file will generate a random number between 1 and 100 • Note that the method “rand” is a static method, so the java file does not need to be instantiated to use it. Call rand with the following: RNG.rand(100) to generate a random number between 0 and 99. • Thank youStudy this class. You will want to use four methods from this class: rand, resetCount, getCount and inputValidation. Driver Class – RandomNumberGuesser • Student created. • This is the driver class for RNG that contains a main method. • The driver is responsible to: o print a header. o ask the user for an initial guess of the Random Number between 0 and 100. o Print out the result for that guess using the methods from the RNG class. o Allow user to give another guess between the previous low and high guesses. o Display the number of guesses. o When user guesses correctly, ask if the user wants to try another round. o Print the Programmer's name at the end. o Refer to the program sample run for more clarification. • Data Validation. The following data is validated by the RNG method inputValidation: o Guesses must be an integer between the previous low guess and high guess. • Naming. o There should be an attribute named randNum. o There should be attributes named nextGuess, highGuess, and lowGuess. • Add any necessary methods to modularize your code
Expert Solution
Step 1

The code for problem is given below with self-explanatory embedded comments.

public class RNG {
  
  private static int count = 0;
  
  // method to generate a random number between 0 and n-1
  public static int rand(int n) {
    return (int)(Math.random() * n);
  }
  // method to reset the count of tries to 0
  public static void resetCount() {
    count = 0;
  }
  // method to retrieve the number of tries
  public static int getCount() {
    return count;
  }
  // method to validate the user's input and increment the count of tries
  public static boolean inputValidation(int guess, int low, int high) {
    count++;
    return (guess >= low && guess <= high);
  }
}

 

 

 

 

 

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Array
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning