Answered step by step
Verified Expert Solution
Question
1 Approved Answer
7. (40 points) Write a Monte Carlo algorithm in Java that computes the probability to win in a game of craps. In this game, we
7. (40 points) Write a Monte Carlo algorithm in Java that computes the probability to win in a game of craps. In this game, we roll two dice and find their sum. There are three possible scenarios leading to a win or loss: If the sum is 7 or 11, we win If the sum is 2, 3, or 12, we lose Otherwise, we roll the dice until we get the initial sum (win) or a sum of 7 (lose) For instance, the following sequences result in a win: - (1,6) // 7 - (6,5) // 11 (2,3), (1,1), (1,4) // initial sum 5 1/2 On the other hand, the following sequences result in a loss: - (1,1) - (2,1) //3 - (4,4), (1,2), (1,6) 1/7 Tips and notes: Write a method that plays a single game of craps Once you have it, you can use it in a loop to count wins vs. #games. The class Random provides nextInt (int n) method which returns a random integer between 0 to n-1
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