/** This program simulates a guessing game. The computer will randomly * think of some number we are to guess. We'll get a certain number of * tries to get it right. Program features a loop and random number * generation. */ import java.util.Scanner; public class Driver { public static void main(String [] args) { Scanner kbd = new Scanner(System.in); // If you need a long string, and you want to continue typing on // another line, close the quote, use "+" and continue the quote // on the next line. System.out.printf("Welcome to my guessing game. Let's see if you can" + " guess my secret number.\n"); // initialize the game Guess game = new Guess(); // Loop until we win or lose the game. We don't know in advance // how many iterations the loop will take, so a while loop seems // appropriate. boolean gameOver = false; while (! gameOver) { System.out.printf("Enter your guess: "); int newGuess = kbd.nextInt(); if (game.good(newGuess)) { System.out.printf("Congratulations! You guessed my number!\n"); gameOver = true; } else if (game.youLose()) { System.out.printf("Sorry, you have run out of guesses. Better luck " + "next time\n"); System.out.printf("The answer was %d.\n", game.giveAnswer()); gameOver = true; } } } } // How could we modify the program so that if we win, it says how many // guesses it took us? Also, think about how we could modify the class so // that it can give advise in case our guess is close or way off?