Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment is an interactive application using indefinite loops to allow th

ID: 3556994 • Letter: T

Question

This assignment is an interactive application using indefinite loops to allow the program to be run repeatedly until the user decides to quit. As usual, we are back to individual assignments. Call your class LastNameHW5 and put it in LastNameHW5.java. (using your own last name!) Turn your file (Java or zip) in electronically using the "Assignment 5 Submission" link on the class web page. Make sure that your code conforms to the conventions covered in class: Indent your code consistently; be consistent with the placement of curly braces. Give meaningful names to methods and variables in your code. Follow Java's naming conventions about the format of ClassNames, methodAndVariableNames, and CONSTANT NAMES. Localize variables whenever possible - that is, declare them in the smallest scope in which they are needed. Use whitespace to separate methods and to generally improve the readability of the code. Avoid line length greater than 80 characters. Include a multiline comment at the top of each program, as in: Write an interactive program that generates a random number between 1 and some max value (maybe 100) and prompts the user repeatedly to guess the number. When the user guesses incorrectly, the game should give the user a hint about whether the correct answer is higher or lower than the guess. Once the user guesses correctly, the program should ask the user if they would like to play again. The game should repeat until the user chooses to quit. When the user chooses to quit, the program should display a summary of statistics including the number of games played, the total number of guesses made, the average number of guesses per game rounded to 2 decimal places, the minimum number of guesses (best game), and the maximum number of guesses (worst game). Your program is required to exactly reproduce the format and behavior as shown in the sample output. Your numbers will be different, but the format and the behavior should be the same. At a minimum, your program should have the following static methods in addition to the main method: a method to give an introduction and instructions to the user a method to play one round of the game with the user (just one game, not multiple games) (Use an indefinite loop in main to repeatedly call the method to play rounds of the game until the user chooses to quit.) a method to ask the user if they would like to play another game - return a boolean a method to ask the user to enter a single guess; insist on an integer input. a method to report overall results to the user when the user decides to quit You may define more methods than this if you find it helpful. Define a class constant for the upper limit used in the guessing game. The sample output shows the user making guesses from 1 to 100, but the choice of 100 is arbitrary. By changing the value of the class constant you should be able to change the upper limit of the range of values the program uses when it generates the random number for the user to guess. For instance, setting the constant to 50 would cause the program to use a range of 1 to 50. Remember to document the class constant with a javadoc comment. For this assignment, do not assume that the user will input reasonable values when prompted. You must check the user input and prompt again if necessary until valid input is obtained. The case study from chapter 5 provides a good example of how to do this. For example, when the user enters a guess, the number entered should be an integer. If the user enters anything other than an integer you should give an error message and prompt again until valid input is entered. When you ask the user whether or not to play again, you should use the "next()" method of the Scanner class to read the user's response as a String. The program should continue to play if the user enters "y" or "Y". The program should end the game and display the final results if the user enters "n" or "N". If the user types anything else, give an error message and prompt again until valid input is entered. Here are a few helpful hints to keep in mind. This program needs to generate pseudorandom numbers. This is described in section 5.1 It's a good idea to change the value of your class constant and run the program to make sure that everything works right with the new value of the constant. Test your program with invalid user input to make sure that the program is robust. Sample Output: (User input in bold) This program allows you to play a guessing game. I will think of a number between 1 and 100 and will allow you to guess until you get it. For each guess, I will tell you whether the right answer is higher or lower than your guess. I'm thinking of a number Your guess? 50 higher Your guess? 75 higher Your guess? 87 lower Your guess? 81 higher Your guess? 84 You got it right in 5 guesses Do you want to play again? Y/N: y I'm thinking of a number Your guess? 50 higher Your guess? 75 lower Your guess? 62 higher Your guess? 68 You got it right in 4 guesses Do you want to play again? Y/N: y I'm thinking of a number Your guess? 50 lower Your guess? Hello Not an integer; try again. Your guess? 4.4 Not an integer; try again. Your guess? 25 higher Your guess? 37 lower Your guess? 31 You got it right in 4 guesses Do you want to play again? Y/N: maybe I did not understand your answer. Do you want to play again? Y/N: N Overall results: total games played = 3 total guesses = 13 average guesses/game = 4.33 minimum guesses = 4 maximum guesses = 5

Explanation / Answer

.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote