Untitled

 avatar
unknown
plain_text
4 years ago
1.6 kB
3
Indexable
import java.util.*;

public class Main {
  public static void main(String[] args) {

    Scanner console = new Scanner(System.in);
    Random rand = new Random();

    int totalGames = 0;
    int totalGuesses = 0;
    int guessesPerGame = 1;
    int bestGame = 0;
    int randomNumber = 0;

    haiku();
    game(guessesPerGame, totalGuesses, randomNumber, console, rand);

  }

  public static void haiku() {
    System.out.println();
    System.out.println("Next blissful fountain");
    System.out.println("A hungry, old lion roars");
    System.out.println("whilst watching the lake");
    System.out.println();
  }

  public static void game(int guessesPerGame, int totalGuesses, int randomNumber, Scanner console, Random rand) {

    System.out.println("I'm thinking of a number between 1 and 100...");
    System.out.print("Your guess? ");
    int userGuess = console.nextInt();
    randomNumber = rand.nextInt(100) + 1;

    while (userGuess != randomNumber) {

      if (userGuess > randomNumber) {
        System.out.println("It's lower.");
      } else {
        System.out.println("It's higher.");
      }
      guessesPerGame += 1;
      System.out.print("Your guess? ");
      userGuess = console.nextInt();

    }

    if (guessesPerGame == 1){
      System.out.println("You got it right in: " + guessesPerGame + " guess!");
    } else if (guessesPerGame > 1) {
      System.out.println("You got it right in: " + guessesPerGame + " guesses!");
    }

    System.out.print("Do you want to play again? ");
    String userAnswer = console.nextLine();

    if (userAnswer == ("yes")) {
      // go back to the while loop
    }

    }

  }
Editor is loading...