Before beginning any work, do a Team...Pull in your repository.
In this lab you will simulate the throw of a number of Dice. This will require using what you have learned in Module 2 and Module 1 but will also require the use of arrays as taught in this module.
We ask that you follow these instructions carefully, step-by-step, so as to develop your code by concept refinement. Each concept is first described, and then your group takes steps to implement the concept.
As an example, if D is 3, then a given throw could be:
As an example, if T is 5, then the dice could be thrown as follows:
At this point,
- Create a class Dice in the lab3 package (which is in the labs source folder).
- Decide on meaningful variable names for the concepts introduced so far:
- The number of dice used in this simulation.
- The number of times the dice are thrown.
- Insert code to obtain the values for these variables from the user.
For the purposes of this lab, let's say that each die is six-sided, and therefore labeled to show the values 1 through 6. If you have time, you might consider how to change your code to accommodate dice that have fewer or more than 6 sides.Iteratively assign all the dice random values.
Spoilers: You will need to sum the values shown on the dice. You should therefore pick a data type that makes this easy.
Consider the example shown in Figure 1. After the first throw, we have:
Recall T was a value prompted from the user. It is the number of times we will throw the dice.
You do not need a different or larger array than the one you already have. You only need to remember the dice values after each throw. You will not be required to remember the values from all of the throws.
Add code to your program so that it computes and prints the fraction of times that all of the dice have the same value in a throw. This requires:
|Sum|| Number of times|
Sum was seen
Some things to keep in mind:Arrange for your program to produce (print) a table such as the one shown above. If you would like columns to line up, then note that when you print output, the String "\t" produces a tab character.
- What values could the sum possibly take, given that there are D dice?
- Based on what we have studied thus far, what type of variable is needed to keep track of the sums?
- Where in your code should you update how often a sum occurs?
For D dice, which sums occur most frequently? You can determine this by running your program on different numbers of dice, but using enough iterations to show typical behavior.
When you are done with this lab, you must be cleared by the TA to receive credit.
- Do a Team…Pull to update your repository. You must do this or the commit/push below may fail.
- Commit and push all your work to your repository.Make certain this has worked by logging into bitbucket. There you will see the commit(s) in your news feed if it was successful. You can also check the Source page to locate and ensure your code was received.
It is your responsibility to make certain the code has been pushed. Some of your work receives credit through testing of your pushed code. You will receive no credit for such work if you failed to push. We generally reserve the right to revoke credit for any of your work that has not been pushed on-time.
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in the TA's name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately, but should be posted in the next day or so
This demo box is for lab 3