Question
Java Program This assignment will give you practice with while loops and pseudorandom numbers. You are going to write a program that allows the user
Java Program
This assignment will give you practice with while loops and pseudorandom numbers. You are going to write a program that allows the user to play a simple game.
The Dice game "Pig" is a game played by the following rules. Each turn a player rolls a single six sided die. If the player rolls a two through six, (2,3,4,5,6) then they get that many points plus they get the option to roll again. On each successive roll they get to add the die roll to their total, and choose again to risk a re-roll.
However, if the player ever rolls a "one"(1) then they get zero points, their turn is over and they lose all the points that have gained for the current round.
So if the player chooses to stop their turn before they roll a one(1) then they get that many points.
For example:
Player 1 rolls a 1. Turn over, score = 0.
Player 2 rolls a 4, chooses to roll again, rolls a 5, chooses to stop. Turn score is a 9, overall score is 9.
Player 1 rolls a 5, then chooses to roll again, rolls a 4, rolls again, rolls a 1. Turn over, turn score is 0, overall score is 0.
Player 2 rolls a 6. Chooses to stop. Turn score is 6, overall score is 15.
Player 1 rolls a 3, then chooses to roll again, rolls a 5, rolls again, gets a 6, rolls again, gets a 4, rolls again, gets a 2, rolls again, gets a 1. Turn over, turn score is 0, overall score is 0.
Player 2 rolls a 4, chooses to roll again, gets a 5, chooses to roll again, gets a 6, chooses to stop. Turn score is 15, overall score is 30.
Game continues...
For the first part of this assignment.
Create a method called playOneTurn() that plays a single Turn with the user. It should roll the dice, ask the user if they want to continue if possible, and returns the round score when finished.
Then using the playOneTurn() method, create a while loop that plays the game between two human players until at least one player has a score of 50 or more. When the game ends, the player with the higher score wins. Note that in each round/loop both players get a turn.
For this assignment you are limited to the language features in Chapters 1-5 shown in lecture or the textbook. You are not allowed to use the break statement or to have a return statement in a void method because these often lead to bad style or use class fields to hold information..
Use whitespace and indentation properly. Give meaningful names to methods and variables, and follow Java's naming standards. Localize variables whenever possible. Include a comment at the beginning of your program with basic description information and a comment at the start of each method. Some students try to achieve repetition without properly using while loops, by writing a method that calls itself; this is not appropriate on this assignment and will result in a deduction in points
Rubric
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