Tracing the DiceUntil9 program
Find the value at various points. They go in order the way the program processes. I filled in the diceValue so that you will know what the randomly generated diceValue became.
Description |
throwCount |
diceValue |
diceCount |
diceTotal |
Line 13 |
|
|
|
|
The first time line 14 is reached (right before it is run) |
|
|
|
|
The first time line 20 is reached (right before it is run) |
|
|
|
|
The first time line 27 is reached (right before it is run) |
|
5 |
|
|
The first time line 29 (the bracket) is reached |
|
5 |
|
|
The second time line 20 is reached (after the number increments and before the test) |
|
5 |
|
|
The second time line 27 is reached (right before it) |
|
1 |
|
|
The second time line 29 (the bracket) is reached. |
|
1 |
|
|
The third time line 20 is reached (after the number increments and before the test) |
|
1 |
|
|
The second time line 14 is reached (right before it). |
|
|
|
|
The next time line 20 is reached (after the number increments and before the test) |
|
|
|
|
The next time line 27 is reached (right before it is run) |
|
4 |
|
|
The next time line 29 (the bracket) is reached |
|
4 |
|
|
The next time line 20 is reached (after the number increments and before the test) |
|
4 |
|
|
The next time line 20 is reached (after the number increments and before the test) |
|
5 |
|
|
The next time line 14 is reached (right before it). |
|
|
|
|
The first time line 33 is reached. |
|
|
|
|
How would you change the diceUntil9.java code to play 20 games,
and count the number of throws it takes to win each game,
and then find the average number of throws to win the game?