Write a java program that simulates a game of dice. In this game, 3 players will take alternate turns rolling two dice. On each turn, they record the sum of the two dice and add this to their total. If a player rolls a doublet (both dice have the same value), then the player gets to roll again until the doublet disappears. After each turn (when both roll), the code checks the sum of each player and the first player to reach a total of 15 or more will win the first place. When a player surpasses 15 but with a doublet (both dice have the same value), the player still gets to roll again until the doublet disappears. The code then checks for the second and third place winners. The code will print out to the user the winners in order. If 2 or all the players hit the same sum, you can consider them all first place winners (for example, if player 1 and 2 hit the same sum that’s >= 15 and 3rd player hits a sum less than 15, then you can say 1st and 2nd players win first place and 3rd wins second place). The same rule applies to a tie for the 2nd place (for example, if player 1 hits the sum that’s >= 15 and player 2 and 3 hit the same sum less than 15, then you can say 1st player wins the first place and 2nd and 3rd players win the second place). For this question, loop(s) and conditionals

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 6SA
icon
Related questions
Question

Write a java program that simulates a game of dice. In this game, 3 players will take alternate
turns rolling two dice. On each turn, they record the sum of the two dice and add this to
their total. If a player rolls a doublet (both dice have the same value), then the player gets
to roll again until the doublet disappears.


After each turn (when both roll), the code checks the sum of each player and the first
player to reach a total of 15 or more will win the first place. When a player surpasses 15
but with a doublet (both dice have the same value), the player still gets to roll again until
the doublet disappears. The code then checks for the second and third place winners. The
code will print out to the user the winners in order.


If 2 or all the players hit the same sum, you can consider them all first place winners (for
example, if player 1 and 2 hit the same sum that’s >= 15 and 3rd player hits a sum less
than 15, then you can say 1st and 2nd players win first place and 3rd wins second place).
The same rule applies to a tie for the 2nd place (for example, if player 1 hits the sum that’s
>= 15 and player 2 and 3 hit the same sum less than 15, then you can say 1st player wins
the first place and 2nd and 3rd players win the second place).


For this question, loop(s) and conditionals 

The output should be as follow (note: no user input is required):
Player 1 rolls a 1 and a 1
Player 1 now has 2
Player 1 rolls a 6 and a 1
Player 1 now has 9
Player 2 rolls a 3 and a 2
Player 2 now has 5
Player 3 rolls a 5 and a 1
Player 3 now has 6
Player 1 rolls a 4 and a 3
Player 1 now has 16
Player 2 rolls a 6 and a 1
Player 2 now has 12
Player 3 rolls a 6 and a 5
Player 3 now has 17
Player 3 wins the first place with a total of 17
Player 1 wins the second place with a total of 16
Player 2 wins the third place with a total of 12
Transcribed Image Text:The output should be as follow (note: no user input is required): Player 1 rolls a 1 and a 1 Player 1 now has 2 Player 1 rolls a 6 and a 1 Player 1 now has 9 Player 2 rolls a 3 and a 2 Player 2 now has 5 Player 3 rolls a 5 and a 1 Player 3 now has 6 Player 1 rolls a 4 and a 3 Player 1 now has 16 Player 2 rolls a 6 and a 1 Player 2 now has 12 Player 3 rolls a 6 and a 5 Player 3 now has 17 Player 3 wins the first place with a total of 17 Player 1 wins the second place with a total of 16 Player 2 wins the third place with a total of 12
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning