Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Driver Need help with the methods. public class RandGuessGame extends java.lang-Object Class for a simple, randomized guessing game. Five integer values between 1 and

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

The Driver

image text in transcribed

Need help with the methods.

public class RandGuessGame extends java.lang-Object Class for a simple, randomized guessing game. Five integer values between 1 and MAX_VALUE (inclusive) will be generated. Only the first and last will be shown to the player. The player must then guess if the sum of all of the numbers is greater than the possible average or not. Field Summary Fields Modifier and Type Field and Description private static int ARR SIZE Number of randomly generated numbers. private int array Sum Stores sum of random values. private char guess Stores player's guess. private int guess Target Number the player must guess against, calculated with MAX_VALUE and ARR_SIZE. private boolean hideMiddleVals Determines if the String returned by toString hides the middle values. private static int MAX_VALUE Maximum value of randomly generated values. private int[] numbers Stores randomly generated numbers for game. private java.util. Random rand Random number generator to use for the game. Constructor Detail RandGuess Game public RandGuess Game (java.util.Random zandIn) Constructor for the RandGuessGame. Creates "numbers" array of size ARR_SIZE to store random values, sets arraySum to zero, and calculates value of "guess Target" by multiplying the amount of numbers by half of "MAX_VALUE". The passed Random object is assigned to the class' Random member. hideMiddlevals is defaulted to "true". Parameters: randIn - The random number generator to be used for this instance of the game. Method Detail populateArray public void populateArray ( ) Populates the "numbers array with random numbers between 1 and "MAX_VALUE". getResult public java.lang.String getResult() Checks to see if player's guess was correct, and constructs and returns a String that reports if they are correct or incorrect, and appends the correct sum of the array. Returns: A String reporting the results of the game. getNumbers public int[] getNumbers () Retrieves the numbers array. Used for testing, do not change. Returns: The numbers array. getArray Sum public int getArrayum) Retrieves the sum of the numbers in the array. Used for testing, do not change. Returns: The value of arrayum. toggle Hidden public void toggleHidden() Toggles the value of hide MiddleVals. If it is currently true, sets it to false, and vice-versa. to String public java.lang.String toString() Returns a String containing the values in the "numbers" array on a single line, separated by spaces with the middle values hidden or all visible based on value of "hide MiddleValue" data member. There is a trailing space on the end, so an example String returned may be: "SXX X 67". NOTE: This does not output to System.out, it generates and returns a String. Overrides: toString in class java.lang. Object Returns: A String with the values of the numbers array. Middle values are hidden if hideMiddleValue is true. validatePlayerGuess public boolean validatePlayerGuess (char guess In) Accepts a user's guess for the game. Validates that it is either the character Y or 'N'. If it is a valid guess, sets the guess data member to the passed value and returns "true". If it is not valid it does not change the value of guess and returns false. Parameters: guessin - The player's guess. Returns: True if the passed guess is valid, false if it is not. getResult public java.lang.String getResult () Checks to see if player's guess was correct, and constructs and returns a String that reports if they are correct or incorrect, and appends the correct sum of the array. Returns: A String reporting the results of the game. public class GameDriver extends java.lang.Object Runs the RandGuessGame. Creates an instance of Rand Guess Game and calls upon its methods to conduct the game. RandGuessGame methods called in order: populateArray outputArray (passing true to hide values) playerGuess getResult outputArray (passing false to show all values)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago