Fixed Price
Budget: $10Start Date
March 1, 2013
PROJECT:
Write a program that simulates playing a million games of craps. From Chapter 5 in our textbook, here are the rules for one game of craps:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll (called “craps”), the player loses (i.e., the “house” wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, then that sum becomes the player’s “point.” To win, the player continues to roll the dice until he/she “makes the point” (making the point means that the dice sum equals the player’s point). To lose, the player rolls a 7 before making the point.
Craps games can have different lengths, where the length of a game is the number of dice rolls required to achieve a win or a loss. Your program should display a histogram that shows two bars (in the form of asterisks) for each number-of-rolls-to-end-the-game scenario. Specifically, show the relative number of games won and the relative number of games lost on the first roll, the relative number of games won and the relative number of games lost on the second roll, etc. Do that for each number-of-rolls scenario for one roll up through ten rolls. In addition, include two bars for the relative number of games won and the relative numbers of games lost for all the games combined that require more than ten rolls. For histogram format details, study the output shown below.
If you’d like to see a histogram program example, see the CoinFlips program from Chapter 9 in the second edition Dean Java textbook (or Chapter 10 in the first edition Dean Java textbook). That program’s histogram prints a total of approximately 100 asterisks. Your program’s histogram should print a total of approximately 200 asterisks. The reason that I can’t says “exactly 200 asterisks” is because calculating the number of asterisks in each bar involves rounding, and it’s possible that the rounding will skew the total number of asterisks slightly above 200 or slightly below 200.
If you borrow code from the craps game program in Chapter 5 in our textbook, be sure to improve the code’s style. For example, enumerated data type declarations should go at the top of your file (not inside main) and enumerated data type tag names should start with a lowercase letter.
As always, you should implement functions to help the main function when it is appropriate to do so. In particular, in the interest of gaining experience with reference parameters, you must implement a play1Game function that uses two reference parameters – won and numOfRolls – that keep track of (1) whether the game resulted in a win, and (2) how many rolls were needed to finish the game.
As always, your program should mimic the given output’s format precisely.
Output:
Histogram showing the likelihood of winning for a given number of rolls.
Rolls
1 wins: ********************************************
losses: **********************
2 wins: ***************
losses: **********************
3 wins: ***********
losses: ****************
4 wins: ********
losses: ***********
5 wins: ******
losses: ********
6 wins: ****
losses: ******
7 wins: ***
losses: ****
8 wins: **
losses: ***
9 wins: *
losses: **
10 wins: *
losses: **
more wins: ***
losses: ****
Activity on this Job
Last Viewed by Client: 3 years ago
Invites Sent: 0
Unanswered Invites: 0
Hired: 1
About the Client
United States
Parkville
10:15 AM
12
Jobs Posted
59% Hire Rate,
1 Open Job
$110
Total Spent
7
Hires,
0
Active