import java.util.*;

/********************************************************
 *
 * Guess plays a guessing game with a user.
 * The program generates a letter from 'a' to 'j' and then 
 * asks the user to guess what letter it is.
 *
 * If the user makes five or fewer guesses to guess the letter, 
 * they win.
 * If it takes them more than five tries they lose.
 * The computer stops the game if the user makes more than 15 tries
 * 
 * This example has an infinite loop.  It will never end the game.
 *
 * @author Nancy Harris and ...
 * @version V1 date
 *********************************************************/
public class Infinite
{
	/******************************************************
	 * main plays the game
	 *
	 * @param args Command line arguments.  Unused in this application
	 ******************************************************/
	public static void main(String args [])
	{
		Scanner kb;
		int randi;
		int guessCount;
		char computerLetter;
		char userLetter;
		char keepGoing;
		String input;
		
		// setup the Scanner
		kb = new Scanner (System.in);

		// Start of outer loop
		System.out.print("Do you want to play a game? " );
		input = kb.nextLine();
		keepGoing = input.charAt(0);
		
		while(keepGoing == 'Y' || keepGoing == 'y')
		{
			// generate the character
			randi = (int)(Math.random() * 10);     // generate random number from 0 - 9
			computerLetter = (char)('a' + randi);  // generates a character from 'a' - 'j'
	
			// as a debugging tool, you might want to print out the computerLetter
			// to see what its value is.
			System.out.println("Computer guess - for debug: " + computerLetter);
	
			// begin your loop...think about the four parts of a loop
			// initialization
			guessCount = 0;
			System.out.print("Enter a character between a and j: ");
			do
			{
				// UPDATE AND BODY
				input = kb.nextLine();
				userLetter = input.charAt(0);
				guessCount = guessCount + 1;
				
				// BODY
				if (userLetter == computerLetter)
					System.out.println("Congratulations, you guessed it!");
				else
					System.out.print("Not correct, try again: ");
			
			}while /* DECISION */
				(userLetter != computerLetter && guessCount < 15);
	
			// output the results		
			if (guessCount <= 5)
				System.out.println("Congratulations, you win!");
			else
				System.out.println("Ha ha ha. I win!");
				
		}
	}
}		