Question

Need .java programme Write a simulation of the Craps dice game. Craps is a dice game...

Need .java programme

Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes.

Craps game rules:First roll:

The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses if the total is a 2, 3, or 12 (“craps”). If any of these five numbers is rolled on the first roll, tally the win or loss, and the round is over.

If none of the above is rolled on a first roll, then the value rolled is saved, i.e., a “point” is established.

Subsequent rolls:

Continue rolling the dice until either a 7 is rolled or the point is rolled.

If the point is rolled before a 7, then tally a win. If a 7 is rolled before the point, tally a loss. Then the round is over.

Program specifications:

  1. 1) Run 100,000 rounds.

  2. 2) Print out information about each round.

  3. 3) Keep track of the wins and losses for all rounds played.

  4. 4) Print out the total number of round wins and losses over 100,000 rounds.

You should print rounds ​exactly ​as shown on the next page. Only print the round information for the first 10 rounds.

The key task, which I suggest you do first, is to get your logic for the game working. After you’ve gotten this working, put this code in a loop and run it for ten or twenty rounds, keeping track of the number of wins and losses, and printing out the total wins and losses at the end. After that, the final touch will be to make the detailed round printing, and then only printing the first ten rounds. Then you can increase the total rounds played to 100,000, and you’re done!

It may be helpful to create a class to store the game information. For instance, you could create a class called CrapsRound that holds the first roll, point, result of the round, and a toString method that prints the round information in the correct format. Then you can create a class that holds an array of CrapsRound objects to simulate running many rounds

Homework Answers

Answer #1

If you have any problem with the code feel free to comment.

Program

public class Test {
   public static void main(String[] args) {
       int total;
       boolean winLoss;
       int win = 0, loss = 0, point = 0;
       System.out.println("*********First 10 Results*********");
       for (int i = 0; i < 100000; i++) {// running loop
           total = getScore();// getting roll score
           if (total == 7 || total == 11) {// first case of win
               winLoss = true;
               win++;
           } else if (total == 2 || total == 3 || total == 13) {// first case of loss
               winLoss = false;
               loss++;
           } else {
               point = total;// initializing point
               while (true) {
                   total = getScore();//getting roll score
                   if (total == point) {//second win case
                       winLoss = true;
                       win++;
                       break;
                   } else if (total == 7) {//second loss case
                       winLoss = false;
                       loss++;
                       break;
                   }
               }
           }

           if (i < 10) {//showing first 10 result
               if (winLoss)
                   System.out.println("Dice Total: " + total + ", Point: " + point + " You Win");
               else
                   System.out.println("Dice Total: " + total + ", Point: " + point + " You Loss");

           }
       }
       //showing total wins and loss
       System.out.println();
       System.out.println("Total wins: " + win);
       System.out.println("Total loss: " + loss);
   }

   private static int getScore() {
       //generating random dice value
       int dice1 = (int) (Math.random() * (6 - 1) + 1);
       int dice2 = (int) (Math.random() * (6 - 1) + 1);
      
       int total = dice1 + dice2;//adding both dice value
       return total;
   }
}

Output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
One of the most popular games of chance is a dice game known as “craps”, played...
One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game: A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins....
Craps is a dice game in which the players make wagers on the outcome of the...
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. Most outcomes depend on the sum of the up faces of two, fair, six-sided dice. A) Describe the sample space for all possible outcomes of rolling two dice. How many ways are there to roll a 5? b)Determine all possible random variable values and the probability of those outcomes. Find the probability of...
Players A and B take turns at rolling two dice, starting with A. The first person...
Players A and B take turns at rolling two dice, starting with A. The first person to get a sum of at least 9 on a roll of the two dice wins the game. Find the probability that A will win the game if: (a) the game is just about to begin (b) 8, 4, 3, 7 and 7 have already been rolled (c) a draw is to be declared in the event of no-one winning within 6 rolls.
Players A and B take turns at rolling two dice, starting with A. The first person...
Players A and B take turns at rolling two dice, starting with A. The first person to get a sum of at least 9 on a roll of the two dice wins the game. Find the probability that A will win the game if: (a) the game is just about to begin (b) 8, 4, 3, 7 and 7 have already been rolled (c) a draw is to be declared in the event of no-one winning within 6 rolls.
Chicago is a group dice game that requires no skill. The objective of the game is...
Chicago is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations (GamezBuff, 2017). How do you play Chicago? There are eleven rounds in the game, one for each combination that can be made by adding two dice, namely the numbers two through 12. Each round has a target combination starting with two and going up all the way to 12. Going clockwise, the players take turns to roll...
Bunco is a group dice game that requires no skill. The objective of the game is...
Bunco is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations. The game is played with three dice, but we will consider a simpler version involving only two dice. How do you play two dice Bunco? There are six rounds, one for each of the possible outcomes in a die, namely the numbers one through six. Going clockwise, players take turns rolling two dice trying to score points....
What is the total probability of rolling a natural on the come-out roll in craps? 2/36...
What is the total probability of rolling a natural on the come-out roll in craps? 2/36 4/36 6/36 8/36 If a player’s point in craps is 8, what is the probability that they will win by rolling another 8 before a 7? 5/36 6/36 5/11 6/11 Assume that rolling an 8 before a 7 will pay at 6-to-5 odds net. Find the net payoff on a $5 wager. $1.20 $5 $6 $11 Find the expected number of 5’s from 100...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
Use CPP This question is about providing game logic for the game of craps we developed...
Use CPP This question is about providing game logic for the game of craps we developed its shell in class. THe cpp of the class is attached to this project. At the end of the game, you should ask user if wants to play another game, if so, make it happen. Otherwise quit. craps.cpp /*** This is an implementation of the famous 'Game of Chance' called 'craps'. It is a dice game. A player rolls 2 dice. Each die has...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT