package loops;

import java.util.*;

public class DoWhileLoopTest {

  public static void main(String[] args) {
    System.out.println("Do While Loop Test");
    Scanner scan = new Scanner(System.in);
    Random rand = new Random();
    int numberOfFlips;
    int randomInteger;
    int count = 0;
    do {
      System.out.print("Enter the number of times to flip a coin: "+
          "(greater than 0): ");
      numberOfFlips = scan.nextInt();
    } while (numberOfFlips <= 0);
    System.out.println("Number of times to flip: " +
                       numberOfFlips);
    for (int i = 0; i < numberOfFlips; i++) {
      randomInteger = rand.nextInt(2);
      if (randomInteger == 0) // 0 represent heads, 1 represent tails
        count++;
    }
    String pluralize = "";
    if (numberOfFlips > 1)
      pluralize = "s";
    System.out.println("The number of heads is " + count + " out of " +
                       numberOfFlips + " flip" + pluralize);
  }
}

