Question: Please using java // Fig. 5.8: Craps.java // Craps class simulates the dice game craps. import java. security.SecureRandom; 1 2 3 4 5 6 7

 Please using java // Fig. 5.8: Craps.java // Craps class simulatesthe dice game craps. import java. security.SecureRandom; 1 2 3 4 56 7 8 9 10 public class Craps { // create securerandom number generator for use in method rollDice private static final SecureRandomrandomNumbers = new SecureRandom(); // enum type with constants that represent thegame status private enum Status {CONTINUE, WON, LOST}; 12 13 14 15

Please using java

// Fig. 5.8: Craps.java // Craps class simulates the dice game craps. import java. security.SecureRandom; 1 2 3 4 5 6 7 8 9 10 public class Craps { // create secure random number generator for use in method rollDice private static final SecureRandom randomNumbers = new SecureRandom(); // enum type with constants that represent the game status private enum Status {CONTINUE, WON, LOST}; 12 13 14 15 16 17 18 // constants that represent common rolls of the dice private static final int SNAKE_EYES = 2; private static final int TREY = 3; private static final int SEVEN = 7; private static final int YO_LEVEN = 11; private static final int BOX_CARS 12; // plays one game of craps public static void main(String[] args) { int myPoint 0; // point if no win or loss on first roll Status gameStatus; // can contain CONTINUE, WON or LOST = int sumOfDice = rolldice(); // first roll of the dice // determine game status and point based on first roll switch (sumOfDice) { case SEVEN: // win with 7 on first roll case YO_LEVEN: // win with 11 on first roll gameStatus = Status. WON; break; case SNAKE_EYES: // lose with 2 on first roll case TREY: // lose with 3 on first roll case BOX_CARS: // lose with 12 on first roll gameStatus = Status.LOST; break; default: // did not win or lose, so remember point gameStatus = Status. CONTINUE; // game is not over myPoint = sumOfDice; // remember the point System.out.printf ("Point is %d%n", myPoint); break; } // while game is not complete while (gameStatus Status. CONTINUE) { // not WON or LOST sumOfDice = rolldice(); // roll dice again == == // determine game status if (sumOfDice myPoint) { // win by making point gameStatus Status. WON; } else { if (sumOfDice SEVEN) { // lose by rolling 7 before point gameStatus Status. LOST; == } } // display won or lost message if (gameStatus == Status. WON) { System.out.println("Player wins"); } else { System.out.println("Player loses"); } } // roll dice, calculate sum and display results public static int rolldice() { // pick random die values int diel = 1 + randomNumbers.nextInt(); // first die roll int die2 1 + randomNumbers.nextInt(); // second die roll = int sum = diel + die2; // sum of die values // display results of this roll System.out.printf("Player rolled %d + %d = %d%n", diel, die2, sum); return sum; } } 11 Player rolled 5 + 6 Player wins Player rolled 5 + 4 = 9 Point is 9 Player rolled 4 + 2 6 Player rolled 3 + 6 9 Player wins = Player rolled 1 + 2 = 3 Player loses Player rolled 2 + 6 = 8 Point is 8 Player rolled 5 + 1 6 Player rolled 2 + 1 3 Player rolled 1 + 6 7 Player loses WO = Q2: Design and implement a game which is meant for two or more players. Each player starts out with 50 points, as each player takes a turn rolling the dice; the amount generated by the dice is subtracted from the player's points. The first player with exactly one point remaining wins. If a player's remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the player's points. (As a alternative, the game can be played with a set number of turns. In this case the player with the amount of points closest to one, when all rounds have been played, wins.) Write a program that simulates the game being played by two players. Use the Die class that was presented during lecture time to simulate the dice. Write a Player class to simulate the player. Enter the player's names and display the die rolls and the totals after each round. // Fig. 5.8: Craps.java // Craps class simulates the dice game craps. import java. security.SecureRandom; 1 2 3 4 5 6 7 8 9 10 public class Craps { // create secure random number generator for use in method rollDice private static final SecureRandom randomNumbers = new SecureRandom(); // enum type with constants that represent the game status private enum Status {CONTINUE, WON, LOST}; 12 13 14 15 16 17 18 // constants that represent common rolls of the dice private static final int SNAKE_EYES = 2; private static final int TREY = 3; private static final int SEVEN = 7; private static final int YO_LEVEN = 11; private static final int BOX_CARS 12; // plays one game of craps public static void main(String[] args) { int myPoint 0; // point if no win or loss on first roll Status gameStatus; // can contain CONTINUE, WON or LOST = int sumOfDice = rolldice(); // first roll of the dice // determine game status and point based on first roll switch (sumOfDice) { case SEVEN: // win with 7 on first roll case YO_LEVEN: // win with 11 on first roll gameStatus = Status. WON; break; case SNAKE_EYES: // lose with 2 on first roll case TREY: // lose with 3 on first roll case BOX_CARS: // lose with 12 on first roll gameStatus = Status.LOST; break; default: // did not win or lose, so remember point gameStatus = Status. CONTINUE; // game is not over myPoint = sumOfDice; // remember the point System.out.printf ("Point is %d%n", myPoint); break; } // while game is not complete while (gameStatus Status. CONTINUE) { // not WON or LOST sumOfDice = rolldice(); // roll dice again == == // determine game status if (sumOfDice myPoint) { // win by making point gameStatus Status. WON; } else { if (sumOfDice SEVEN) { // lose by rolling 7 before point gameStatus Status. LOST; == } } // display won or lost message if (gameStatus == Status. WON) { System.out.println("Player wins"); } else { System.out.println("Player loses"); } } // roll dice, calculate sum and display results public static int rolldice() { // pick random die values int diel = 1 + randomNumbers.nextInt(); // first die roll int die2 1 + randomNumbers.nextInt(); // second die roll = int sum = diel + die2; // sum of die values // display results of this roll System.out.printf("Player rolled %d + %d = %d%n", diel, die2, sum); return sum; } } 11 Player rolled 5 + 6 Player wins Player rolled 5 + 4 = 9 Point is 9 Player rolled 4 + 2 6 Player rolled 3 + 6 9 Player wins = Player rolled 1 + 2 = 3 Player loses Player rolled 2 + 6 = 8 Point is 8 Player rolled 5 + 1 6 Player rolled 2 + 1 3 Player rolled 1 + 6 7 Player loses WO = Q2: Design and implement a game which is meant for two or more players. Each player starts out with 50 points, as each player takes a turn rolling the dice; the amount generated by the dice is subtracted from the player's points. The first player with exactly one point remaining wins. If a player's remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the player's points. (As a alternative, the game can be played with a set number of turns. In this case the player with the amount of points closest to one, when all rounds have been played, wins.) Write a program that simulates the game being played by two players. Use the Die class that was presented during lecture time to simulate the dice. Write a Player class to simulate the player. Enter the player's names and display the die rolls and the totals after each round

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!