Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise Overview Implement a Java program that is based on the simulated roll of 3 dice. Player scores points based on the combination of (1)
Exercise Overview
Implement a Java program that is based on the simulated roll of 3 dice.
- Player scores points based on the combination of (1) the sum of the dice and (2) bonus points from rolling a pair, a triple, or a straight (3 numbers in a row).
- Player rolls 3 dice in the first roll, and then decides for each die whether to roll again or lock the value of a die in order to improve the score hence, the name Lock N Roll.
- At the beginning of the game, player will enter his/her name and the number of turns they wish to have in a single game. A turn is an initial roll plus the second roll after lock/reroll.
- After all turns have been played, the program will print a history of the turns showing the players initial roll score, final roll score, and the improvement after the Lock N Roll action.
- Player is prompted to play again or not.
Functional Requirements (how the code will work from the user perspective)
- System displays the rules of the game on the console.
- Player enters his/her name.
- Player enters the number of turns to be taken in the game. A turn consists of the initial role and the second (final) roll.
- System displays the initial roll including values of the 3 dice, sum of the 3 dice, bonus points, and total points.
- System indicates progression to the Lock N Roll phase.
- Player indicates Lock or Roll for each die. Player can lock 0 to 3 dice or roll 0 to 3 dice.
- After Lock N Roll, die/dice designated for Roll are rolled for new value(s).
- System analyzes the new set of dice to determine bonus points.
- System displays the second roll including values of the 3 dice, sum of the 3 dice, bonus points, and total points. If all dice were locked, the values from the initial roll are the values for the second roll. Turn is completed.
- If turn completion is not the last turn in the game, a new turn begins starting with the initial roll.
- If turn completion marks the last turn in the game, system displays the turn history, including initial and final dice values, final sum, final bonus points, final total points, and points improved from initial to final roll for each turn in the game.
- Player is prompted to indicate whether to play again or not, and responds with Y or N.
Technical Requirements (how you must code it)
The system should include the following Java components:
- System consists of 5 phases. Use this in your Design discussion.
- Introduction and printing the rules to console.
- Initial roll of the 3 dice.
- Lock N Roll, where player indicates whether to lock or roll each die.
- Second roll after the Lock N Roll, including final score of the turn. This includes end of the turn, printing of turn results, and triggers the start of the next turn (phase 2 again, if another turn is required).
- After turns in the game are completed, system prints to console a summary of the players performance for each turn.
- Final dice values for both rolls.
- Final sum, pair, triple, straight values.
- Final roll total points.
- Points improved from initial to final roll.
- Name of your source code main class as follows: YourName_Project1.java
- Variables (other than local vars) should be declared at the beginning of the main method.
- Use arrays for storing of dice values, e.g., int[] roll1 = new int[3];
- Methods to implement for the following functions.
- Sort the dice.
- Evaluate dice values for a pair.
- Evaluate dice values for a triple.
- Note: if dice indicate a triple, then no pair bonus is earned.
- Evaluate dice values for a straight.
- Print turn history at end of game.
- while or for loop to execute the indicated number of turns.
- Algorithm for generating the random die values using Random class.
- System.out.printf() method for formatting of printing turn, roll, and game results.
- String array to store the values associated with each turn.
- do-while loop to enable continuous play with Y/N response.
- for loops for various activities updating dice values, printing of turn history, etc. especially for those associated with arrays.
Hints and Suggestions
- Read the submission instructions and grading rubric at the end of this document.
- While writing code, print variable values to console frequently as a form of testing.
- Use comments to label the different sections (and subsections) of your code.
- Create a single String record variable for each turn. This would be the variable that is an element in the String array that stores the turn history.
- Remember to discuss how you tested the accuracy and effectiveness of your random-value generating algorithm.
- The method for sorting the dice can be implemented with ~20 or fewer lines of code.
- Alternatively, you can use the method Arrays.sort(arg) which takes an array as an argument and returns that array sorted.
- You can find information for Arrays.sort() in several places, but here is one that is quite straightforward.
- Alternatively, you can use the method Arrays.sort(arg) which takes an array as an argument and returns that array sorted.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started