import java.util.*;

public class Yahtzee {
    public static final int NUMBER_REROLLS=2;

    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        DiceCup dc = new DiceCup();

        for (int i = 0; i < NUMBER_REROLLS; i++) {
            System.out.println(dc); //prints the dice
            if (dc.isYahtzee()) // no need to continue if we got Yahtzee
            {
                break;
            }
            System.out.print("Which dice do you want to reroll: ");
            dc.rollDice(convert(keyboard.nextLine())); //reads the dice
            //to reroll and rerolls them
        }
        System.out.println(dc); //prints the dice
        if (dc.isYahtzee()) {
            System.out.println("You got Yahtzee!");
        } else {
            System.out.println("Sorry, better luck next time!");
        }
    }

    static int[] convert(String s) {

        StringTokenizer st = new StringTokenizer(s);

        int[] a = new int[st.countTokens()];
        int i = 0;

        while (st.hasMoreTokens()) {
            a[i++] = Integer.parseInt(st.nextToken());
        }

        return a;
    }
}