Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Play the game of Craps. The basic bet made by the \"shooter\" in this game is th

ID: 3788967 • Letter: P

Question

Play the game of Craps. The basic bet made by the "shooter" in this game is the pass-line bet. To start a pass-line bet, the shooter makes a "come-out" roll. Roll the pair of dice. If the "come-out" roll is a 2, 3, or 12 that is called "craps" or "crapping out" and the shooter immediately loses. A "come-out" roll of 7 or 11 is a "natural" and the shooter immediately wins. The other possible numbers are the point numbers: 4. 5, 6, 8, 9 and 10. If the shooter rolls one of these numbers on the come-out roll, this establishes the "point". To win. the point number must be rolled again before a seven (7). So, in the case where a "point" is established the shooter rolls over and over until cither the point is rolled (a win) or a seven (7) is rolled (a loss). Using your Periodic class write an application that simulates 100 pass-line bets and output the results of each bet to an output file. Also, keep a running total of how many wins and losses. Output those totals at the end of your run.

Explanation / Answer

PairOfDice.java

public class PairOfDice
{
public int d1;
public int d2;

public PairOfDice() {
}

   public void Roll()
   {
   this.d1 = (int )(Math.random() * 6 + 1);
   this.d2 = (int )(Math.random() * 6 + 1);      
   }

   public String toString()
   {
String r;
   r = this.d1 + " + " + this.d2 + " = " + (this.d1 + this.d2) ;
   return r;
   }

   public int summ()
   {
   return (this.d1 + this.d2);      
   }

}

Driver.java

import java.io.PrintWriter;
import java.io.File;
public class Driver
{
public static void main(String[] args) throws Exception
{
PrintWriter writer = new PrintWriter("output.txt", "UTF-8");
PairOfDice d = new PairOfDice();
int i = 0;
int wins = 0;
int loses = 0;
while(i<100)
{
writer.println(i+1);
d.Roll();
int mysum = d.summ();
if(mysum == 2 || mysum == 3 || mysum == 12)
{
writer.println("You Rolled " + d.toString());
writer.println("You lose!");
loses = loses + 1;
}
else if(mysum == 7 || mysum == 11)
{
writer.println("You Rolled " + d.toString());
writer.println("You win!");
wins = wins + 1;
}
else
{
writer.println("You Rolled " + d.toString());
writer.println("Point is " + mysum);
int point = mysum;
while(true)
{
d.Roll();
writer.println("You Rolled " + d.toString());
mysum = d.summ();
if(mysum == point)
{
writer.println("You win!");
wins = wins + 1;
break;
}
else if(mysum == 7)
{
writer.println("You lose!");
loses = loses + 1;
break;
}
}
}
i =i + 1;
}
writer.println("Tatal wins = " + wins);
writer.println("Tatal loses = " + loses);
writer.close();
}

}

Output.txt

1
You Rolled 2 + 6 = 8
Point is 8
You Rolled 6 + 4 = 10
You Rolled 2 + 4 = 6
You Rolled 1 + 2 = 3
You Rolled 5 + 4 = 9
You Rolled 4 + 3 = 7
You lose!
2
You Rolled 3 + 1 = 4
Point is 4
You Rolled 5 + 6 = 11
You Rolled 5 + 2 = 7
You lose!
3
You Rolled 1 + 5 = 6
Point is 6
You Rolled 6 + 4 = 10
You Rolled 5 + 5 = 10
You Rolled 5 + 2 = 7
You lose!
4
You Rolled 1 + 2 = 3
You lose!
5
You Rolled 3 + 6 = 9
Point is 9
You Rolled 6 + 2 = 8
You Rolled 1 + 3 = 4
You Rolled 1 + 4 = 5
You Rolled 6 + 4 = 10
You Rolled 3 + 3 = 6
You Rolled 1 + 5 = 6
You Rolled 2 + 3 = 5
You Rolled 2 + 4 = 6
You Rolled 4 + 4 = 8
You Rolled 3 + 2 = 5
You Rolled 5 + 4 = 9
You win!
6
You Rolled 5 + 3 = 8
Point is 8
You Rolled 2 + 1 = 3
You Rolled 6 + 4 = 10
You Rolled 3 + 3 = 6
You Rolled 1 + 6 = 7
You lose!
7
You Rolled 3 + 5 = 8
Point is 8
You Rolled 4 + 1 = 5
You Rolled 2 + 5 = 7
You lose!
8
You Rolled 1 + 1 = 2
You lose!
9
You Rolled 4 + 4 = 8
Point is 8
You Rolled 5 + 6 = 11
You Rolled 5 + 6 = 11
You Rolled 2 + 6 = 8
You win!
10
You Rolled 1 + 3 = 4
Point is 4
You Rolled 5 + 4 = 9
You Rolled 1 + 5 = 6
You Rolled 5 + 1 = 6
You Rolled 6 + 6 = 12
You Rolled 3 + 3 = 6
You Rolled 1 + 6 = 7
You lose!
11
You Rolled 6 + 5 = 11
You win!
12
You Rolled 6 + 6 = 12
You lose!
13
You Rolled 1 + 4 = 5
Point is 5
You Rolled 6 + 4 = 10
You Rolled 6 + 6 = 12
You Rolled 5 + 4 = 9
You Rolled 4 + 6 = 10
You Rolled 2 + 1 = 3
You Rolled 6 + 1 = 7
You lose!
14
You Rolled 5 + 2 = 7
You win!
15
You Rolled 6 + 2 = 8
Point is 8
You Rolled 6 + 6 = 12
You Rolled 4 + 6 = 10
You Rolled 2 + 6 = 8
You win!
16
You Rolled 4 + 1 = 5
Point is 5
You Rolled 1 + 1 = 2
You Rolled 4 + 4 = 8
You Rolled 5 + 5 = 10
You Rolled 6 + 1 = 7
You lose!
17
You Rolled 6 + 6 = 12
You lose!
18
You Rolled 2 + 2 = 4
Point is 4
You Rolled 4 + 6 = 10
You Rolled 1 + 2 = 3
You Rolled 3 + 3 = 6
You Rolled 5 + 6 = 11
You Rolled 3 + 6 = 9
You Rolled 1 + 5 = 6
You Rolled 4 + 1 = 5
You Rolled 6 + 4 = 10
You Rolled 6 + 4 = 10
You Rolled 6 + 5 = 11
You Rolled 3 + 5 = 8
You Rolled 2 + 1 = 3
You Rolled 4 + 6 = 10
You Rolled 4 + 3 = 7
You lose!
19
You Rolled 3 + 3 = 6
Point is 6
You Rolled 4 + 3 = 7
You lose!
20
You Rolled 5 + 3 = 8
Point is 8
You Rolled 2 + 3 = 5
You Rolled 2 + 2 = 4
You Rolled 3 + 4 = 7
You lose!
21
You Rolled 4 + 5 = 9
Point is 9
You Rolled 5 + 1 = 6
You Rolled 6 + 3 = 9
You win!
22
You Rolled 5 + 1 = 6
Point is 6
You Rolled 6 + 4 = 10
You Rolled 5 + 5 = 10
You Rolled 1 + 2 = 3
You Rolled 1 + 6 = 7
You lose!
23
You Rolled 3 + 3 = 6
Point is 6
You Rolled 5 + 5 = 10
You Rolled 6 + 4 = 10
You Rolled 1 + 1 = 2
You Rolled 6 + 4 = 10
You Rolled 3 + 3 = 6
You win!
24
You Rolled 2 + 2 = 4
Point is 4
You Rolled 2 + 6 = 8
You Rolled 2 + 2 = 4
You win!
25
You Rolled 2 + 2 = 4
Point is 4
You Rolled 5 + 1 = 6
You Rolled 3 + 5 = 8
You Rolled 3 + 3 = 6
You Rolled 1 + 5 = 6
You Rolled 6 + 3 = 9
You Rolled 6 + 1 = 7
You lose!
26
You Rolled 4 + 3 = 7
You win!
27
You Rolled 5 + 1 = 6
Point is 6
You Rolled 1 + 1 = 2
You Rolled 6 + 5 = 11
You Rolled 3 + 3 = 6
You win!
28
You Rolled 2 + 3 = 5
Point is 5
You Rolled 6 + 6 = 12
You Rolled 3 + 6 = 9
You Rolled 3 + 4 = 7
You lose!
29
You Rolled 4 + 5 = 9
Point is 9
You Rolled 4 + 1 = 5
You Rolled 3 + 4 = 7
You lose!
30
You Rolled 1 + 1 = 2
You lose!
31
You Rolled 1 + 4 = 5
Point is 5
You Rolled 6 + 1 = 7
You lose!
32
You Rolled 1 + 5 = 6
Point is 6
You Rolled 2 + 5 = 7
You lose!
33
You Rolled 5 + 1 = 6
Point is 6
You Rolled 5 + 6 = 11
You Rolled 6 + 2 = 8
You Rolled 5 + 2 = 7
You lose!
34
You Rolled 3 + 3 = 6
Point is 6
You Rolled 1 + 6 = 7
You lose!
35
You Rolled 6 + 4 = 10
Point is 10
You Rolled 2 + 4 = 6
You Rolled 4 + 3 = 7
You lose!
36
You Rolled 4 + 3 = 7
You win!
37
You Rolled 5 + 4 = 9
Point is 9
You Rolled 5 + 2 = 7
You lose!
38
You Rolled 1 + 1 = 2
You lose!
39
You Rolled 5 + 4 = 9
Point is 9
You Rolled 4 + 2 = 6
You Rolled 1 + 2 = 3
You Rolled 3 + 4 = 7
You lose!
40
You Rolled 1 + 1 = 2
You lose!
41
You Rolled 3 + 2 = 5
Point is 5
You Rolled 4 + 4 = 8
You Rolled 1 + 1 = 2
You Rolled 6 + 4 = 10
You Rolled 6 + 2 = 8
You Rolled 3 + 1 = 4
You Rolled 1 + 1 = 2
You Rolled 3 + 4 = 7
You lose!
42
You Rolled 5 + 2 = 7
You win!
43
You Rolled 5 + 4 = 9
Point is 9
You Rolled 1 + 4 = 5
You Rolled 3 + 5 = 8
You Rolled 1 + 2 = 3
You Rolled 5 + 5 = 10
You Rolled 3 + 1 = 4
You Rolled 4 + 5 = 9
You win!
44
You Rolled 1 + 4 = 5
Point is 5
You Rolled 6 + 4 = 10
You Rolled 6 + 4 = 10
You Rolled 6 + 4 = 10
You Rolled 3 + 6 = 9
You Rolled 2 + 6 = 8
You Rolled 5 + 2 = 7
You lose!
45
You Rolled 2 + 3 = 5
Point is 5
You Rolled 3 + 1 = 4
You Rolled 5 + 2 = 7
You lose!
46
You Rolled 6 + 6 = 12
You lose!
47
You Rolled 3 + 5 = 8
Point is 8
You Rolled 2 + 2 = 4
You Rolled 4 + 5 = 9
You Rolled 6 + 5 = 11
You Rolled 4 + 6 = 10
You Rolled 2 + 2 = 4
You Rolled 1 + 2 = 3
You Rolled 1 + 1 = 2
You Rolled 1 + 1 = 2
You Rolled 2 + 3 = 5
You Rolled 5 + 4 = 9
You Rolled 4 + 3 = 7
You lose!
48
You Rolled 3 + 6 = 9
Point is 9
You Rolled 6 + 2 = 8
You Rolled 3 + 4 = 7
You lose!
49
You Rolled 6 + 6 = 12
You lose!
50
You Rolled 4 + 3 = 7
You win!
51
You Rolled 4 + 3 = 7
You win!
52
You Rolled 6 + 6 = 12
You lose!
53
You Rolled 4 + 1 = 5
Point is 5
You Rolled 6 + 3 = 9
You Rolled 6 + 6 = 12
You Rolled 4 + 1 = 5
You win!
54
You Rolled 3 + 1 = 4
Point is 4
You Rolled 2 + 4 = 6
You Rolled 2 + 2 = 4
You win!
55
You Rolled 4 + 3 = 7
You win!
56
You Rolled 5 + 1 = 6
Point is 6
You Rolled 2 + 1 = 3
You Rolled 6 + 6 = 12
You Rolled 2 + 6 = 8
You Rolled 4 + 2 = 6
You win!
57
You Rolled 3 + 2 = 5
Point is 5
You Rolled 4 + 4 = 8
You Rolled 5 + 3 = 8
You Rolled 2 + 2 = 4
You Rolled 2 + 3 = 5
You win!
58
You Rolled 4 + 1 = 5
Point is 5
You Rolled 1 + 3 = 4
You Rolled 6 + 1 = 7
You lose!
59
You Rolled 6 + 3 = 9
Point is 9
You Rolled 3 + 4 = 7
You lose!
60
You Rolled 1 + 6 = 7
You win!
61
You Rolled 2 + 2 = 4
Point is 4
You Rolled 4 + 3 = 7
You lose!
62
You Rolled 3 + 3 = 6
Point is 6
You Rolled 1 + 4 = 5
You Rolled 4 + 5 = 9
You Rolled 5 + 6 = 11
You Rolled 2 + 6 = 8
You Rolled 6 + 3 = 9
You Rolled 3 + 2 = 5
You Rolled 4 + 1 = 5
You Rolled 2 + 5 = 7
You lose!
63
You Rolled 6 + 5 = 11
You win!
64
You Rolled 2 + 5 = 7
You win!
65
You Rolled 4 + 1 = 5
Point is 5
You Rolled 5 + 3 = 8
You Rolled 2 + 1 = 3
You Rolled 2 + 3 = 5
You win!
66
You Rolled 3 + 3 = 6
Point is 6
You Rolled 4 + 1 = 5
You Rolled 6 + 6 = 12
You Rolled 5 + 2 = 7
You lose!
67
You Rolled 5 + 5 = 10
Point is 10
You Rolled 1 + 6 = 7
You lose!
68
You Rolled 3 + 2 = 5
Point is 5
You Rolled 5 + 2 = 7
You lose!
69
You Rolled 2 + 6 = 8
Point is 8
You Rolled 3 + 3 = 6
You Rolled 2 + 1 = 3
You Rolled 5 + 2 = 7
You lose!
70
You Rolled 3 + 2 = 5
Point is 5
You Rolled 6 + 4 = 10
You Rolled 3 + 6 = 9
You Rolled 1 + 1 = 2
You Rolled 5 + 1 = 6
You Rolled 5 + 6 = 11
You Rolled 2 + 1 = 3
You Rolled 5 + 3 = 8
You Rolled 3 + 2 = 5
You win!
71
You Rolled 6 + 6 = 12
You lose!
72
You Rolled 3 + 2 = 5
Point is 5
You Rolled 1 + 4 = 5
You win!
73
You Rolled 1 + 1 = 2
You lose!
74
You Rolled 3 + 1 = 4
Point is 4
You Rolled 1 + 2 = 3
You Rolled 1 + 4 = 5
You Rolled 6 + 6 = 12
You Rolled 5 + 4 = 9
You Rolled 6 + 4 = 10
You Rolled 5 + 3 = 8
You Rolled 2 + 4 = 6
You Rolled 5 + 3 = 8
You Rolled 1 + 3 = 4
You win!
75
You Rolled 1 + 3 = 4
Point is 4
You Rolled 5 + 5 = 10
You Rolled 2 + 3 = 5
You Rolled 2 + 3 = 5
You Rolled 1 + 1 = 2
You Rolled 2 + 2 = 4
You win!
76
You Rolled 5 + 5 = 10
Point is 10
You Rolled 1 + 2 = 3
You Rolled 5 + 1 = 6
You Rolled 1 + 1 = 2
You Rolled 3 + 3 = 6
You Rolled 4 + 1 = 5
You Rolled 4 + 4 = 8
You Rolled 1 + 6 = 7
You lose!
77
You Rolled 6 + 5 = 11
You win!
78
You Rolled 6 + 5 = 11
You win!
79
You Rolled 5 + 6 = 11
You win!
80
You Rolled 4 + 3 = 7
You win!
81
You Rolled 3 + 5 = 8
Point is 8
You Rolled 2 + 4 = 6
You Rolled 5 + 3 = 8
You win!
82
You Rolled 1 + 3 = 4
Point is 4
You Rolled 4 + 5 = 9
You Rolled 3 + 1 = 4
You win!
83
You Rolled 4 + 2 = 6
Point is 6
You Rolled 2 + 4 = 6
You win!
84
You Rolled 6 + 6 = 12
You lose!
85
You Rolled 4 + 5 = 9
Point is 9
You Rolled 6 + 3 = 9
You win!
86
You Rolled 5 + 4 = 9
Point is 9
You Rolled 4 + 4 = 8
You Rolled 3 + 3 = 6
You Rolled 2 + 6 = 8
You Rolled 6 + 2 = 8
You Rolled 2 + 6 = 8
You Rolled 6 + 3 = 9
You win!
87
You Rolled 3 + 2 = 5
Point is 5
You Rolled 2 + 1 = 3
You Rolled 3 + 2 = 5
You win!
88
You Rolled 5 + 1 = 6
Point is 6
You Rolled 3 + 1 = 4
You Rolled 4 + 1 = 5
You Rolled 4 + 2 = 6
You win!
89
You Rolled 1 + 1 = 2
You lose!
90
You Rolled 3 + 1 = 4
Point is 4
You Rolled 1 + 6 = 7
You lose!
91
You Rolled 1 + 6 = 7
You win!
92
You Rolled 5 + 1 = 6
Point is 6
You Rolled 4 + 3 = 7
You lose!
93
You Rolled 4 + 2 = 6
Point is 6
You Rolled 1 + 4 = 5
You Rolled 1 + 3 = 4
You Rolled 3 + 4 = 7
You lose!
94
You Rolled 1 + 3 = 4
Point is 4
You Rolled 1 + 5 = 6
You Rolled 3 + 4 = 7
You lose!
95
You Rolled 2 + 6 = 8
Point is 8
You Rolled 5 + 4 = 9
You Rolled 1 + 2 = 3
You Rolled 3 + 6 = 9
You Rolled 3 + 4 = 7
You lose!
96
You Rolled 6 + 2 = 8
Point is 8
You Rolled 4 + 6 = 10
You Rolled 5 + 6 = 11
You Rolled 5 + 5 = 10
You Rolled 2 + 6 = 8
You win!
97
You Rolled 4 + 3 = 7
You win!
98
You Rolled 6 + 3 = 9
Point is 9
You Rolled 3 + 3 = 6
You Rolled 5 + 4 = 9
You win!
99
You Rolled 4 + 6 = 10
Point is 10
You Rolled 6 + 5 = 11
You Rolled 5 + 5 = 10
You win!
100
You Rolled 1 + 2 = 3
You lose!
Tatal wins = 44
Tatal loses = 56