public class Dice {
  //code for exercise 11

  public static void main(String[] args) {

    System.out.print("How many 6s in a row do you want to roll -> ");
    int in = IOUtil.readInt();
    System.out.println("It took " + numberOf6Rolls(in));
    System.out.println("It took " + numberOf6Rolls1(in));
    System.out.println("It took " + numberOf6Rolls2(in));
  }

  private static int rollDie() {
    return (int) (Math.random() * 6) + 1;
  }

  private static int numberOf6Rolls(int n) {
    assert (n > -1) : "must be a non-negative number";
    int count = 0;
    int count6 = 0;
    while (count6 < n) {
      count++;
      if (rollDie() == 6) {
        count6++;
      } else {
        count6 = 0;
      }
    }
    return count;
  }

  private static int numberOf6Rolls1(int n) {
    int diceThrown = 0;

    outer:
    while (true) {
      for (int i = 0; i < n; i++) {
        int attempt = rollDie();
        diceThrown++;
        if (attempt != 6) {
          continue outer;
        }
      }
      break;
    }

    return diceThrown;
  }

  private static int numberOf6Rolls2(int n) {
    //isn't this much more complicated (and horrible)?
    //avoid breaks and continues if you can
    assert (n > -1) : "must be a non-negative number";
    int count = 0;

    while (true) {
      boolean cont = false;
      for (int i = 0; i < n; i++) {
        count++;
        if (rollDie() != 6) {
          cont = true;
          break;
        }
      }
      if (!cont) {
        break;
      }

    }
    return count;
  }
}


