APlusGrades

Not Rated (0)

$15/per page/Negotiable

About APlusGrades

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing,Foreign Languages,Geography,Geology,Health & Medical,HR Management,Law,Management,Physics,Programming,Science,Statistics Hide all
Teaching Since: Jul 2017
Last Sign in: 364 Weeks Ago, 2 Days Ago
Questions Answered: 1850
Tutorials Posted: 1850

Education

  • Graduate in Biology and Nutrition, MBA Finance
    Florida State University
    Aug-2000 - Jul-2007

Experience

  • Ass. Relationship Manager
    Penn-Florida
    Mar-2009 - Feb-2016

Category > Programming Posted 16 Jul 2017 My Price 11.00

import java

I just do not know how to get the value of "totalGuesses" and "bestGame" in the report value. I think there should be a return method but I did not know how to do that.

Please help me because I spent 2 days on it, tried so hard and so mad now.

Please just use those skills that I used in this program, not include "do/while" and "static int" and so on...

 

*"Best game" means the least times to get the correct answer.

Thx.

 

import java.util.*;

 

public class Guess1 {

  public static final int MAX = 100;

  public static void main(String[] args) {

   Scanner console = new Scanner(System.in);

   Random r = new Random();

   int totalGames = 0;

   int numGuesses = 0;

   int totalGuesses = 0;

   intro();

   playGame(r, console, numGuesses, totalGuesses);

   next(r, console, totalGames, numGuesses, totalGuesses);

  }

  

  public static void intro() {

   System.out.println("This program allows you to play a guessing game.");

   System.out.println("I will think of a number between 1 and " + MAX);

   System.out.println( "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 right answer is higher or lower");

   System.out.println("than your guess.");

  }

  

  public static void playGame(Random r, Scanner console, int numGuesses, int totalGuesses) {

   System.out.println();

   System.out.println("I am thinking of a number between 1 and " + MAX + "...");

   int compNum = r.nextInt(MAX) + 1;

   System.out.println(compNum);

   int userNum = -1;

   numGuesses = 0;

   while (compNum != userNum) {

     numGuesses++;

     totalGuesses++;

     System.out.print("Your guess? ");

     userNum = console.nextInt();

     if (compNum > userNum) {

      System.out.println("It's higher.");

     } else if (compNum < userNum) {

      System.out.println("It's lower.");

     }

   }

   if (numGuesses == 1) {

     System.out.println("You got it right in 1 guess");

   } else {

     System.out.println("You got it right in " + numGuesses + " guesses");

   }

   

  }

  

  public static void next(Random r, Scanner console, int totalGames, int numGuesses, int totalGuesses) {

   System.out.print("Do you want to play again? ");

   String answer = console.next();

   totalGames = 1;

   if (answer.startsWith("y") || answer.startsWith("Y")) {

     playGame(r, console, numGuesses, totalGuesses);

     next(r, console, totalGames, numGuesses, totalGuesses);

   } else if (answer.startsWith("n") || answer.startsWith("N")) {

     report(totalGames, totalGuesses);     

   }

  }

  

  public static void report(int totalGames, int totalGuesses) {

     System.out.println();

     System.out.println();

     System.out.println("Overall results: ");

     System.out.println("  total games = " + totalGames);

     System.out.println("  total guesses = " + totalGuesses);

     System.out.println("  guesses/game = ");

     System.out.println("  best game = ");

 

  }

Answers

Not Rated (0)
Status NEW Posted 16 Jul 2017 08:07 AM My Price 11.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â-----------  -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I

Not Rated(0)