Question Details

(Solved) I just wanna know how to get value of "totalGuesses" in "report" method; I spent most of my time on it but I could not handle it....


I just wanna know how to get value of "totalGuesses" in "report" method;

I spent most of my time on it but I could not handle it.

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


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")) {

     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 = ");

     

   }

  }

}

 


Solution details:
STATUS
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Sep 05, 2019

PRICE: $15

Solution~000200183455.zip (25.37 KB)

Buy this answer for only: $15

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 05, 2019

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.

Order Now