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

ory Bookmarks Window Help csus.instructure.com roject 3 Concert Report 2-Google

ID: 3707446 • Letter: O

Question

ory Bookmarks Window Help csus.instructure.com roject 3 Concert Report 2-Google Docs Craps Game Note: For this program a shell has not been provided to you. You need to read the assignment completely and make sure that you understand the rules of the game by reading about it online as well. Problem In the game of craps, a pass line bet proceedsas folows. Two sie-sided die are rolled the frs roll of the dice in a craps round is called the "come out roll: A come out roll of 7 or 11 automatically wins, and a come out roll of 2.3, or 12 automatically loses. If 4,5,6,8,9, or 10is rolled on the come out roll that number becomes "the point The player keeps rolling the dice until either 7 or the point is rolled.If the point is rolled first, then the player wins the bet. If a 7 is rolled first, then the player loses. Write a program that smula the program should calculate whether the player would win or lose. The program should simulate rolling two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins and how many times the player loses. At the end of the 10,000 games, compute the probability of winning (wins/ (wins+ losses]) and output this value. Note: to simulate the dice rolling use the Random class to generate numbers between 1 and 6 inclusive. Here is an example series: tes a game of craps using these rules without human input. Instead of asking for a wage, The shooter throws the dice on a come out roll, which starts a new series, and a 5 is rolled. (Recall that rolling a 7 or 11 would have been winners and 2, 3, or 12 would have been losers) The shooter has established a point of 5 The shooter throws the dice again and rolls an 8 Nothing happens and player rolls the dice again The shooter throws the dice again and rolls a 3. INote that rolling a 2, 3, 11, or 12 after a point is established means nothing) . The shooter throws the dice again and rolls a 5 This is the shooter's point so this is a win and the series ends Your program should: MacBook Pro 3 4 5 0

Explanation / Answer

Hi,
I already coded for this craps game previously....please find the class & it might be helpful to you.....if you find any queries please revert back to me........
////////////////////////////////Craps.java//////////////////////
import java.util.Random;
import java.util.Scanner;
public class Craps {
public static int play(){
int total = roll();
System.out.println("The total you got after Rolling: "+total);
if (total ==7 || total == 11) return 1;
else if (total ==2 ||total == 3 || total == 12 ) return 0;
else return point(total);
}
public static int point(int total) {
System.out.println("Again Rolling.......");
int results = roll();
while(1>0){
if(results==total){
return 1;
}
else if(results==7){
return 0;
}
else{
System.out.println("Again Rolling.......");
results = roll();
}
}
}
public static int roll(){
Random rand = new Random();
int d1 = rand.nextInt(6);
if(d1==0) d1=d1+1;
System.out.println("Dice-1 Value:"+d1);
displayRoll(d1);
int d2 = rand.nextInt(6);
if(d2==0) d2=d2+1;
System.out.println("Dice-2 Value:"+d2);
displayRoll(d2);
return d1+d2;
}
public static void displayRoll(int value) {
switch(value){
case 1:
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 2:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 3:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
break;
case 4:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
case 5:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
break;
case 6:
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
System.out.println("*");
System.out.println();
System.out.println(" *");
System.out.println();
break;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(1>0){
System.out.println("Press 'y' to play......Press 'n' to exit:");
String input = sc.next();
System.out.println(input);
if(input.equalsIgnoreCase("y")){
System.out.println("Your Game Starts:");
int results = play();
if(results==1){
System.out.println("Hurray...You won the game :)");
}
else{
System.out.println("Opps......You Lose the Game");
}
}
else if(input.equalsIgnoreCase("n")){
System.out.println("Bye...Bye...");
break;
}
}
}
}