Using java, need to create a craps game program that can keep track on a user's wins / losses and also prompt user to place bets.
Using java, need to create a craps game program that can keep track on a user's wins / losses and also prompt user to place bets.

Craps is a dice game in which the players make wagers on the outcome of the roll or a series of rolls of a pair of dice.
Each round has 2 phases: Come Out and Point.
A Come Out roll of 2, 3, or 12 are called Craps as the shooter is said to 'crap out' ending the round with players losing their Pass Line bets.
A Come Out roll of 7 or 11 is called a Natural resulting in a win for Pass Line bets.
The shooter continues to make Come Out rolls until he rolls 4, 5, 6, 8, 9, or 10, which number becomes the Point.
The dealer then moves an On button to the point number that indicates the second phase of the round.
If the shooter rolls the point number, the result is a win for bets on the Pass Line.
If the shooter rolls a seven (a Seven-out), the pass line loses and the round ends.
The complete Java code for the Craps game is given below:
import java.util.*;
import java.util.Random;
public class Main
{
public static void main(String[] args) throws java.lang.Exception {
int wins = 0;
int loss = 0;
Scanner sc1= new Scanner(System.in);
System.out.print("Enter the number of Rolls: ");
int n= sc1.nextInt();
for (int i = 0; i <n; i++) {
System.out.println("Roll the dices");
Scanner sc= new Scanner(System.in);
System.out.print("Enter Your Bet: ");
int a= sc.nextInt();
int score = roll();
System.out.println("\n score " + score);
if (score == 7 || score == 11) {
System.out.println("\n Score = " + score);
System.out.println("User wins");
wins = wins + 1;
} else if (score == 2 || score == 3 || score == 12) {
System.out.println("\n Score = " + score);
System.out.println("User loses");
loss = loss + 1;
} else {
int point = score;
System.out.println("\n Point = " + point);
while (true) {
score = roll();
System.out.println("\n Score new = " + score);
if (score == point) {
System.out.println("\n User wins");
wins = wins + 1;
break;
}
if (score == 7) {
System.out.println("\n User loses");
loss = loss + 1;
break;
}
}
}
}
System.out.println("\n Number of wins by the user = " + wins
+ " and Number of losses by the user = " + loss);
}
public static int roll() {
Random randomGenerator = new Random();
int dice1 = randomGenerator.nextInt(6) + 1;
int dice2 = randomGenerator.nextInt(6) + 1;
System.out.println("\n dice1 = " + dice1 + " dice2 = " + dice2);
return dice1 + dice2;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images









