-
Notifications
You must be signed in to change notification settings - Fork 0
/
nested_Ver1.java
176 lines (139 loc) · 5.04 KB
/
nested_Ver1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package java_craps;
import java.util.*;
public class crapsArray {
public static void main(String[] args) {
// first turn starts here
int players;
Scanner input = new Scanner(System.in);
// resume next round loop
String nextRound = "";
do
{
System.out.println("Would you like to play this round? Enter \"yes\" to play again, and \"no\" to quit.");
nextRound = input.nextLine();
if (!nextRound.equalsIgnoreCase("yes"))
{
do
{
System.out.print("Welcome to the craps table! How many players will be playing? (maximum of 6) ");
players = input.nextInt();
}
while (players > 6);
double[] firstBet = new double[players];
for(int pos = 0; pos < firstBet.length; pos ++)
{
System.out.print("Player " + (pos +1) + ", how much would you like to bet? ");
firstBet[pos] = input.nextDouble();
}
System.out.print("Which player will be rolling the dice? ");
int playerTurn = input.nextInt();
System.out.print("Player " + playerTurn + ", please enter \"roll\" to roll the dice. ");
String discard = input.next();
System.out.println();
Random rand = new Random();
int die1 = rand.nextInt(6) + 1;
int die2 = rand.nextInt(6) + 1;
int sumPassRound = die1 + die2;
System.out.println("You rolled: " + die1 + " + " + die2 + " = " + sumPassRound);
// sumPassRound = 8;
System.out.println("You rolled " + sumPassRound);
if(sumPassRound == 7 || sumPassRound == 11)
{
System.out.println("Congratulations! You won.");
for(int pos = 0; pos < firstBet.length; pos++)
{
System.out.println("Player " + (pos+1) + ", you won $" + firstBet[pos] + "!");
}
}
else
{
if(sumPassRound == 2 || sumPassRound == 3 || sumPassRound == 12)
{
System.out.println("Sorry, you have lost.");
for(int pos = 0; pos < firstBet.length; pos++)
{
System.out.println("Player " + (pos+1) + ", you have lost $" + firstBet[pos] + ".");
}
}
else
{
System.out.println("You rolled " + sumPassRound + ". This is your point value as we proceed to the point round.");
System.out.println();
}
double[] secondBet = new double[players];
for(int pos = 0; pos < secondBet.length; pos++)
{
secondBet[pos] = 0;
}
char[] forOrAgainst = new char[players];
for(int pos = 0; pos < secondBet.length; pos ++)
{
System.out.print("Player " + (pos +1) + ", how much would you like to bet in the point round? (enter 0 if not) ");
secondBet[pos] = secondBet[pos] + input.nextDouble();
System.out.print("Player " + (pos +1) + ", would you like to bet for or against the point value? Enter 'f' for for and 'a' for against. ");
forOrAgainst[pos] = input.next().charAt(0);
}
System.out.println();
int sumPointRound = 0;
int die3;
int die4;
double[] odds = new double[11]; //{2,1.5,1.2,1.2,1.5,2}
odds[0] = 1; //odds on a 2
odds[1] = 1; //odds on a 3
odds[2] = 2; //odds on a 4
odds[3] = 1.5; //odds on a 5
odds[4] = 1.2; //odds on a 6
odds[5] = 1; //odds on a 7
odds[6] = 1.2; //odds on an 8
odds[7] = 1.5; //odds on a 9
odds[8] = 2; //odds on a 10
odds[9] = 1; //odds on an 11
odds[10] = 1; //odds on a 12
while (sumPointRound != 7 && sumPointRound != sumPassRound)
{
die3 = rand.nextInt(5) + 1;
die4 = rand.nextInt(5) + 1;
sumPointRound = die3 + die4;
System.out.println("You rolled: " + die3 + " + " + die4 + " = " + sumPointRound);
}
//sumPointRound = 8;
if(sumPointRound == 7)
{
System.out.println("If you bet for the point, you have lost. If you bet against the point, you have won!");
for(int pos = 0; pos < secondBet.length; pos++)
{
if(forOrAgainst[pos] == 'f')
{
System.out.println("Player " + (pos+1) + ", you have lost $" + (firstBet[pos] + secondBet[pos]) + ".");
}
else
{
System.out.println("Player " + (pos+1) + ", you have won $" + (firstBet[pos] + (secondBet[pos] *
(1/(odds[sumPassRound - 2])))) + "! This is less than the amount "
+ "you bet because of the odds of rolling each different number.");
}
}
}
if(sumPointRound == sumPassRound)
{
System.out.println("If you bet for the point, you have won! If you bet against the point, you have lost.");
for(int pos = 0; pos < secondBet.length; pos++)
{
if(forOrAgainst[pos] == 'a')
{
System.out.println("Player " + (pos+1) + ", you have lost $" + (firstBet[pos] + secondBet[pos]) + ".");
}
else
{
System.out.println("Player " + (pos+1) + ", you have won $" + (firstBet[pos] +
(secondBet[pos] * odds[sumPointRound-2])) + "! This is more than the amount you bet because "
+ "of the odds of rolling each different number.");
}
while(!nextRound.equalsIgnoreCase("no"));
}
}
}
}
}
}
}