The starter code does contain formatting mistakes .The output must match the sample output exactly.The user must be prompted for a seed for the random number generator and then an indeterminate number of integer-guesses until the game terminates (by matching an integer-guess to the target-integer).Any integer may be used as the seed and as a guess.The program must not discriminate a user's guess. A guess that contradicts a hint ('too high' or 'too low') or is repeated is a valid guess.Instance variables/constants may not be used. In general, content not formally presented in the class heretofore cannot be used. main() method must call the following two programmer-defined methods (methods that you write):A process non-void method that returns the number of user-attempts to guess the random-number correctly and an output void method that displays the final results of the program (the number of guess required to correctly guess the random number).process method must call the following programmer-defined method (a method that you write): An input non-void method to (depending upon the String variable/literal used as a parameter (or argument) to specify the appropriate prompt to the user) will either be called once in order to return the user-defined seed or be called an indefinite number of times in order to return a user-defined guess. the main() method should only contain: a salutation (to the user), the constant called MAX that defines the maximum possible random number, the Scanner object and a primitive variable (used to store the number of guesses) declaration, the two method calls to the programmer-defined methods (the methods that you write), and one method call to the Scanner object (that does not read from the input buffer!). the main() method may either contain the loop to govern the game (and be subject to a deduction) or call a process non-void method that contains the loop to govern the game and return the number of guess required to correctly guess the random number. Use the most appropriate loop to manage the game. the only Scanner object must be declared in the main() method; do not move the Scanner object declaration nor declare another Scanner object in the program The constant called MAX must be declared atop the main() method and effectively used in the program to generate random numbers. In general, avoid using 'magic numbers' in code because 'magic numbers' reduce code-readability. An integer constant/variable should not appear in the code except for possibly common integers, such as 0 or 1. every method should be preceded with a comment that includes a description of the method purpose and the value returned (if applicable)! Comments should also be included in the body of each method. Development Strategy: Initially, complete the code entirely in the main() method. Only after the code is functional (using only the main() method) should the code be parsed into methods; add methods singularly (one at a time) and carefully vet the the code with the added method before adding the next method until all methods are added. Input-Method: In order to reduce the number of input-methods from three to one, simply use a String variable/literal as a parameter (or argument) that specifies the prompt needed for the particular user-defined integer (seed to the random number generator (RNG), a guess, or a response corresponding to a desire to repeat the game). String variable as a Parameter: Use a String variable (instead of a literal) for the input method to obtain the user-defined guesses to differentiate the first guess from the subsequent guesses that may be too low or too high. Random Object Scope: The process-method should contain the Random object.Hardcode the Target-Number: During program-development, hardcode the target-number in order to ensure the loop and logic ('too high' or 'too low') are correct. Then, after the loop and logic are functional, make the number random. Debug Print-Statements: Employ a debug print-statements that temporarily displays the target-number and the user-defined guesses during program-development to ensure program-integrity (especially regarding the hint ('too high' or 'too low'). Remove the debug print-statements before submitting the assignment! SAMPLE OUTPUT Welcome to the Guessing Game! Enter a seed: 33 Please enter a number between 1 and 100: 5 Too high. Guess again:  4 Congratulations. You guessed correctly!  You needed 2 guesses.   Welcome to the Guessing Game!   Enter a seed: 50 Please enter a number between 1 and 100: 50 Too high. Guess again:  25 Too high. Guess again:  12 Too low. Guess again:  19 Too high. Guess again:  15 Too low. Guess again:  17 Too low. Guess again:  19 Too high. Guess again:  18 Congratulations. You guessed correctly!  You needed 8 guesses.   Welcome to the Guessing Game!   Enter a seed: 0 Please enter a number between 1 and 100: 61   Congratulations. You guessed correctly!  You needed only 1 guess.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The starter code does contain formatting mistakes .The output must match the sample output exactly.The user must be prompted for a seed for the random number generator and then an indeterminate number of integer-guesses until the game terminates (by matching an integer-guess to the target-integer).Any integer may be used as the seed and as a guess.The program must not discriminate a user's guess. A guess that contradicts a hint ('too high' or 'too low') or is repeated is a valid guess.Instance variables/constants may not be used. In general, content not formally presented in the class heretofore cannot be used. main() method must call the following two programmer-defined methods (methods that you write):A process non-void method that returns the number of user-attempts to guess the random-number correctly and an output void method that displays the final results of the program (the number of guess required to correctly guess the random number).process method must call the following programmer-defined method (a method that you write): An input non-void method to (depending upon the String variable/literal used as a parameter (or argument) to specify the appropriate prompt to the user) will either be called once in order to return the user-defined seed or be called an indefinite number of times in order to return a user-defined guess. the main() method should only contain:

      • a salutation (to the user),
      • the constant called MAX that defines the maximum possible random number,
      • the Scanner object and a primitive variable (used to store the number of guesses) declaration,
      • the two method calls to the programmer-defined methods (the methods that you write), and
      • one method call to the Scanner object (that does not read from the input buffer!).
    • the main() method may either
      • contain the loop to govern the game (and be subject to a deduction) or
      • call a process non-void method that contains the loop to govern the game and return the number of guess required to correctly guess the random number.
    • Use the most appropriate loop to manage the game.
    • the only Scanner object must be declared in the main() method; do not move the Scanner object declaration nor declare another Scanner object in the program
    • The constant called MAX must be declared atop the main() method and effectively used in the program to generate random numbers. In general, avoid using 'magic numbers' in code because 'magic numbers' reduce code-readability. An integer constant/variable should not appear in the code except for possibly common integers, such as 0 or 1.
    • every method should be preceded with a comment that includes a description of the method purpose and the value returned (if applicable)! Comments should also be included in the body of each method.

Development StrategyInitially, complete the code entirely in the main() method. Only after the code is functional (using only the main() method) should the code be parsed into methods; add methods singularly (one at a time) and carefully vet the the code with the added method before adding the next method until all methods are added.

Input-Method: In order to reduce the number of input-methods from three to one, simply use a String variable/literal as a parameter (or argument) that specifies the prompt needed for the particular user-defined integer (seed to the random number generator (RNG), a guess, or a response corresponding to a desire to repeat the game).

String variable as a Parameter: Use a String variable (instead of a literal) for the input method to obtain the user-defined guesses to differentiate the first guess from the subsequent guesses that may be too low or too high.

Random Object Scope: The process-method should contain the Random object.Hardcode the Target-Number: During program-development, hardcode the target-number in order to ensure the loop and logic ('too high' or 'too low') are correct. Then, after the loop and logic are functional, make the number random.

Debug Print-Statements: Employ a debug print-statements that temporarily displays the target-number and the user-defined guesses during program-development to ensure program-integrity (especially regarding the hint ('too high' or 'too low'). Remove the debug print-statements before submitting the assignment!

SAMPLE OUTPUT

Welcome to the Guessing Game!

Enter a seed:
33

Please enter a number between 1 and 100:
5
Too high. Guess again: 
4

Congratulations. You guessed correctly! 
You needed 2 guesses.

 

Welcome to the Guessing Game!

 

Enter a seed:
50

Please enter a number between 1 and 100:
50
Too high. Guess again: 
25
Too high. Guess again: 
12
Too low. Guess again: 
19
Too high. Guess again: 
15
Too low. Guess again: 
17
Too low. Guess again: 
19
Too high. Guess again: 
18

Congratulations. You guessed correctly! 
You needed 8 guesses.

 

Welcome to the Guessing Game!

 

Enter a seed:
0

Please enter a number between 1 and 100:
61
 

Congratulations. You guessed correctly! 
You needed only 1 guess.

 

```java
import java.util.Scanner;

public class GuessANumber_Part1 {
    public static void main(String[] args) {
        // ======= INSERT YOUR CODE HERE ==========
        //Declare a Constant
        ???

        //Declare the Scanner object.
        //Note: Only one Scanner object may exist in a program and the Scanner
        //      declaration must remain in the main() method but be used in an
        //      "input()" method.
        ???
        
        // Call the following TWO (2) methods (and then write the method
        //   implementations) that:
        // 1) uses the Scanner object and the constant to play the game and get the 
        //    number of user-attempts to guess the random-number correctly.
        //    Note: This method will
        //    A) call the input-method once to obtain the seed for the random 
        //       number generator (RNG) and
        //    B) call the input-method an indeterminate number of times to 
        //       obtain the user-defined guesses.
        //    Note: Methods can indeed call other methods!
        // 2) uses a local variable that stores the number of guesses to print the
        //    program results.
        ???
    }
}
```

This code represents a Java template for a guessing game program. The main goal is to set up a guessing game where the user attempts to guess a random number. In the given template:

- **Declare a Constant**: You need to define a constant, likely to set the upper limit for the random number or similar game conditions.
- **Scanner Object**: A `Scanner` object is used for getting input from the user. Only one instance is allowed, and it should be declared in the `main` method, although it will be used elsewhere in the program.
- **Method Implementation**: You are expected to implement two methods:
  1. A method that uses the `Scanner` and the constant to manage:
     - Random number generation using a seed input.
     - Collecting user guesses.
  2. A method that keeps track of the number of guesses and prints the results.

This is an educational exercise to practice object declaration, method implementation, and input handling in Java.
Transcribed Image Text:```java import java.util.Scanner; public class GuessANumber_Part1 { public static void main(String[] args) { // ======= INSERT YOUR CODE HERE ========== //Declare a Constant ??? //Declare the Scanner object. //Note: Only one Scanner object may exist in a program and the Scanner // declaration must remain in the main() method but be used in an // "input()" method. ??? // Call the following TWO (2) methods (and then write the method // implementations) that: // 1) uses the Scanner object and the constant to play the game and get the // number of user-attempts to guess the random-number correctly. // Note: This method will // A) call the input-method once to obtain the seed for the random // number generator (RNG) and // B) call the input-method an indeterminate number of times to // obtain the user-defined guesses. // Note: Methods can indeed call other methods! // 2) uses a local variable that stores the number of guesses to print the // program results. ??? } } ``` This code represents a Java template for a guessing game program. The main goal is to set up a guessing game where the user attempts to guess a random number. In the given template: - **Declare a Constant**: You need to define a constant, likely to set the upper limit for the random number or similar game conditions. - **Scanner Object**: A `Scanner` object is used for getting input from the user. Only one instance is allowed, and it should be declared in the `main` method, although it will be used elsewhere in the program. - **Method Implementation**: You are expected to implement two methods: 1. A method that uses the `Scanner` and the constant to manage: - Random number generation using a seed input. - Collecting user guesses. 2. A method that keeps track of the number of guesses and prints the results. This is an educational exercise to practice object declaration, method implementation, and input handling in Java.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Hiring Problem
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education