SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

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 Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 11 Dec 2017 My Price 8.00

make print best guesses with the least amount of guesses

Wanted to make print best guesses with the least amount of guesses but can't seem to get my code to work please help.

 

 

import java.util.*;

 

public class Guess {

  

  public static int userGuesses;

  public static int userGames;

  

  public static void main(String[] args) {

   Intro();

   Scanner prompt = new Scanner(System.in);

   game();

  }

  

  //Introduction to the User

  

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

   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 right answer is higher or lower");

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

   System.out.println();

  }

  

  //Finds random number and prompts user to guess the number, then giving hints

  

  public static double game() {

   userGames++;

   Random goal = new Random();

   Scanner prompt = new Scanner(System.in);

   System.out.println("I'm thinking of a number between 1 and 100...");

   int output = goal.nextInt(5);

   int userInput = -1;

   while (userInput != output) {

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

     userInput = prompt.nextInt();

     userGuesses++;

     if (userInput < output) {

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

     }

     else if (userInput > output) {

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

     }

     else {

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

     }

   }

   again(prompt);

   return userInput;

    

  }

  

  //Reports the results to the console if user decides to stop playing

  

  public static double results() {

   int userInput = 0;

   System.out.println();

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

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

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

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

 

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

 

 

   return userInput;

  }

  

  //Asks user if he would like to play again

  

  public static double again(Scanner prompt) {

   String input = null;

   int userInput = 0;

   Scanner console = new Scanner(System.in);

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

   input = console.nextLine();

   if (input.equals("Y")) {

     return game();

   }

   else if (input.equals("y")) {

     return game();

   }

   else if (input.equals("N")) {

     return results();

   }

   else if (input.equals("n")) {

     return results();

   }

   return userInput;

    

  }

}

Answers

(5)
Status NEW Posted 11 Dec 2017 02:12 PM My Price 8.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)