Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help solving this assignment for java Methods At a minimum, your program should have the following static methods in addition to method main: a

need help solving this assignment for java

Methods

At a minimum, your program should have the following static methods in addition to method main:

  • a method that introduces the game to the user
  • a method to play one game with the user (just one game, not multiple games)
  • a method to report overall results to the user

You may define more methods than this if you find it helpful, although you will find that the limitation that methods can return only one value will tend to limit how much you can decompose this problem.

Max Guess

You are to define a class constant for the maximum number 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 introducing a constant for 100, you should be able to change just the value of the constant to make the program play the game with a range of 1 to 50 or a range of 1 to 250 or some other range starting with 1.

Playing again

When you ask the user whether or not to play again, you should use the next() method of the Scanner class to read a one-word answer from the user.

You should continue playing if this answer begins with the letter y or the letter Y. Notice that the user is allowed to type words like yes. You are to look just at the first letter of the users response and see whether it begins with a y or n (either capitalized or not) to determine whether to play again.

Assume Good Input

Assume that the user always types an integer when guessing, that the integer is always in an appropriate range and that the user gives you a one-word answer beginning with y, Y, n or N when asked whether to play again.

End statistics

You will notice at the end of the output that you are to report various statistics about the series of games played by the user. You are to report

  • the total number of games played,
  • the total number of guesses made (all games included),
  • the average number of guesses per game, and
  • the best (fewest) number of guesses used in any single game.

The average number of guesses per games should be rounded to one decimal place (use printf).

please no arrays we only went through paramters if else and while loops.

this is what i have so far

public static void gameIntro() { System.out.println("This program will allow you to play a guessing game."); System.out.println("I will think of a number between 1 and"); System.out.println("100 and will allow you to guess until"); System.out.println("you get it. For each guess, I will tell you"); System.out.println("whether the answer is higher or lower"); System.out.println("than your guess."); } for the intro and

beginning

public class GuessingGame { public static final int MAX = 100; public static void main(String[] args) { Scanner console = new Scanner(System.in); Random numberGenerator = new Random();

and the getting stats

public static void getGameStats(int bestGuess, int games, int totalGuesses) { System.out.println("Overall results:"); System.out.println(" total games = " + games); System.out.println(" total guesses = " + totalGuesses); System.out.println(" guesses/game = " + roundNumber(totalGuesses/games)); System.out.println(" best game = " + bestGuess); } public static double roundNumber(double number) { return (Math.round(number * 10)) / 10.0; }

i need help with the main method and the playing the game portion.

sample

This program allows you to play a guessing game. It will think of a number between 1 and 100 and will allow you to guess until you get it. For each guess, It will tell you whether the correct answer is higher or lower than your guess. I'm thinking of a number between 1 and 100... Your guess? 50 It's lower. Your guess? 25 It's lower. Your guess? 12 It's lower. Your guess? 6 You got it right in 4 guesses Do you want to play again? y I'm thinking of a number between 1 and 100... Your guess? 50 It's lower. Your guess? 25 It's lower. Your guess? 12 It's higher. Your guess? 18 You got it right in 4 guesses Do you want to play again? YES I'm thinking of a number between 1 and 100... Your guess? 50 It's higher. Your guess? 75 It's lower. Your guess? 62 It's higher. Your guess? 68 It's lower. Your guess? 65 It's higher. Your guess? 66 It's higher. Your guess? 67 You got it right in 7 guesses Do you want to play again? nope Game statistics: total games = 3 total guesses = 15 guesses/game = 5.0 best game = 4

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

2. What is their level of comprehension?

Answered: 1 week ago