// FlipCoin.java

public class FlipCoin
{
  public static void main(String[] args) throws Exception
  {

    char userInput = 'z';

    while(userInput != 'a' && userInput != 'b')
    {
      // Prompt user to guess heads or tails
      System.out.println("Enter (a) heads or (b) tails: ");
	  userInput = (char) System.in.read();
	  System.in.read();System.in.read();

      if (userInput != 'a' && userInput != 'b')

      System.out.println("Sorry, you didn't enter a " +
                         "or b ; please try again.");
    }

    // Choose a random number
    double randomNumber = Math.random();

    // Determine whether user guessed correctly
    if (userInput == 'a' && randomNumber < 0.5)
      System.out.println("You win!");
    else if (userInput == 'b' && randomNumber >= 0.5)
      System.out.println("You win!");
    else
      System.out.println("Sorry, you lose.");
  }
}
