CS 122 - Homework #3 - Yahtzee simulation - due February 13, 2019 This program will be called Yahtzee.java. Write a program that will allow the user to play one turn of the game Yahtzee. Yahtzee is a dice game that is reminiscent of the card game poker. In Yahtzee, the player rolls five dice. The object of the game is to achieve certain valuable patterns among the five numbers that appear on the dice. The five dice can be called a "hand" just as in poker. After rolling the dice once, the player has two opportunities to improve the hand. In such an opportunity, the player selects which of the five dice should be re-rolled. The player may select any number of dice (zero to five) to re-roll. After the third and final roll, it is time to evaluate the hand and assign a point value to it. In Yahtzee, seven types of hands are possible. Name of hand Definition Point value ---------------+--------------------------+--------------- Yahtzee | All five dice show | 50 | the same number. | ---------------+--------------------------+--------------- Large straight | The five dice form a | | continuous sequence of | 40 | values, as in: | | 1,2,3,4,5 or 2,3,4,5,6. | ---------------+--------------------------+--------------- Small straight | Only four of the dice | | form a continuous | | sequence of values, | 30 | as in: 1,2,3,4 or | | 2,3,4,5 or 3,4,5,6. | ---------------+--------------------------+--------------- 4 of a kind | Exactly 4 of the dice | the sum of | show the same number. | the dice ---------------+--------------------------+--------------- Full house | Three of the dice show | | the same number, and | | the remaining two dice | 25 | show a different | | matching number, as in: | | 3,3,3,5,5 | ---------------+--------------------------+--------------- 3 of a kind | Exactly three of the | | dice show the same | the sum of | number, and it's not a | the dice | full house. | ---------------+--------------------------+--------------- Chance | None of the above. | the sum of | | the dice ---------------+--------------------------+--------------- This game will be run interactively at the keyboard. We will not use command-line arguments. In order to facilitate the testing of your program, I have decided not to use Java's random number generator to create random input. Instead, the program will ask the user to supply the name of an input file that contains 15 random numbers. These random numbers will represent the rolls of the dice that the program might need. Note that in the most extreme case, the program will need to roll all five dice three times, requiring all 15 random numbers. As an example, you can create a text file called lucky.txt, containing just one line of text, with these numbers: 4 3 2 5 5 1 1 3 2 4 5 6 1 6 3 Here is how the program should play the game: 1. As mentioned above, ask the user to enter the file name containing the 15 random dice rolls. Your program should assume that all 15 numbers are on the first and only line in the file. The numbers will be separated by one or more space characters. 2. Show the player the result of the first roll of the dice. These numbers will come from the first 5 values in the input file. Every time the program displays the five dice to the player, they must be sorted in ascending order. I recommend that you use the built-in Java method Arrays.sort() immediately before you print out the hand. 3. Ask the user which of the 5 die positions should be replaced. The die positions are numbered 1-5. The user will enter up to five positions, separated by one or more spaces. The user does not have to enter these positions in any particular order. It's also possible for the user to not specify any die positions to replace by typing no numbers and hitting enter. You may assume that the user will enter legitmate input. All die positions entered by the user will be distinct. 4. For each die position specified by the user, the program needs to consult the next unused value in the input file to use as a replacement die value. For example, let's suppose the original hand is 2 3 4 5 5. The player specifies that die positions 1 and 3 (containing the values 2 and 4, respectively) are to be replaced. The 2 and the 4 would be replaced with the 6th and 7th numbers in the input file. No value in the input file will be used twice, so it will be necessary for your program to keep track of how many random die values have been "dealt." 5. Repeat steps 2-4: Show the player the result of the second roll of the dice, and give the player a second opportunity to replace die positions. Don't forget to sort the hand ascendingly. 6. Finally, show the (sorted) third roll to the player. At this point, the program should evaluate the hand according to the table above, and announce the result. The type of hand must be spelled exactly as in the table above. Please follow the format of I/O exactly as follows in these examples: Welcome to Yahtzee! What file contains rolls of the dice? lucky.txt Here is your first roll: 2 3 4 5 5 Which die positions (1-5) would you like to replace? Hit enter if none. 5 Here is your second roll: 1 2 3 4 5 Which die positions (1-5) would you like to replace? Hit enter if none. Here is your final roll: 1 2 3 4 5 Large straight. 40 points Welcome to Yahtzee! What file contains rolls of the dice? lucky.txt Here is your first roll: 2 3 4 5 5 Which die positions (1-5) would you like to replace? Hit enter if none. 1 2 3 Here is your second roll: 1 1 3 5 5 Which die positions (1-5) would you like to replace? Hit enter if none. 3 Here is your final roll: 1 1 2 5 5 Chance. 14 points