Part 2 The question in this part of the assignment will be g

Part 2 The question in this part of the assignment will be graded. Question 1: Craps (100 points) dice rolls. The goal this question is Craps is a dice game where each player bets on the outcome of the of to write several methods in order to create a program that simulates the outcome of a Pass Line Bet (see below) in a game of Craps. All the code for this question must be placed in a file named Gambling java. The Pass Line Bet Craps is a game of rounds. The first dice roll of a round is called the come-out Roll, When a player is making a Pass Line Bet, they will place a bet before the come-out R on the result of the roll, the player might win, lose, or go to the \"next stage\" of the game If a 7 or an 11 is rolled, then the player wins. If a 2, 3, or 12 is rolled, then the player loses. If any other number is rolled, the player must go to the next stage. For the next stage, it is important to remember which number was rolled in the Come-out Roll, this number is called the point. In the second stage, the player will keep rolling the dice until one of the following happens: A 7 is rolled, and the player loses the bet The point is rolled again, and the player wins the bet The payout is 1:1: the players win as much as he bets. Thus, if the player bets S5 and wins he will receive an additional S5. If he loses, he will lose the entire bet. Let\'s see a couple of examples: The result of the Come Out Roll is a 3. The player loses! The result of the Come-out Roll is a 5 The dice are rolled again until either a 7 or a 5 is rolled Supposed that the results of the rolls are the following: 10, 11, 4, 7. The player loses! The result of the Come-out Roll is a 9 The dice are rolled again until either a 7 or a 9 is rolled. Let the results of the rolls be as follow: 3, 5, 9. The player wins! Now that we now how the game works, let\'s see which methods we need to simulate the result of a Pass Line bets in a game of Craps. la. A method to simulate a dice roll In a game of Craps, players are betting on the outcome of a rol two six-sided dice, Write a method called dice Roll that simulates roll of dice. Such me wil return an int muda uncluded, which is the sum of the result of rolling wo six-sided di Notice, that to simulate the roll of two six-sided dice, you will have to generate two rand and 6 (both included) the results together. If you h roubts on how to achieve this, make sure you first understand the warm-up Question 4, where you are asked to build a method called enerate Radom numbers get Random Numbers

Solution

import java.util.Random;

public class Gambling {

   static Random rn = new Random();
  
  
   static int diceRoll()
   {
       int n1 = rn.nextInt(6) + 1;
       int n2 = rn.nextInt(6) + 1;
       return n1+n2;
   }
  
   static boolean canPlay(double balance, double bet)
   {
       return balance >= bet;
   }
  
   static int secondStage(int point)
   {
       int d;
       while(true)
       {
           d = diceRoll();
          
           if (d == point || d == 7)
           {
               System.out.println(d);
               break;
           }
               System.out.print(d+\",\");
       }
       return d;
   }
  
   static double passLineBet(double balance, double bet)
   {
       if (canPlay(balance, bet))
       {
           int d = diceRoll();
           boolean win = true;
           if (d == 7 || d == 11)
           {
               System.out.println(\"A \" + d + \" has been rolled. You win!\");
           }
           else
           {
               if (d == 2 || d == 3 || d == 12)
               {
                   System.out.println(\"A \" + d + \" has been rolled. You lose!\");
                   win = false;
               }
               else
               {
                   System.out.println(\"A \" + d + \" has been rolled. Roll again!\");
                   d = secondStage(d);
          
                   if (d == 7)
                   {
                       System.out.println(\"A \" + d + \" has been rolled. You lose!\");
                       win = false;
                   }
                   else
                   {
                       System.out.println(\"A \" + d + \" has been rolled. You win!\");
                   }
               }
           }
           if (win)
               return (balance + bet);
           else
               return (balance - bet);
       }
       else
           System.out.println(\"Balance is insufficient to place the bet.\");
       return balance;
   }

   public static void main(String[] args)
   {
       double money = 0;
       double bet = 0;
      
       if (args.length == 2)
       {
           try
           {
               money = Double.parseDouble(args[0]);
               bet = Double.parseDouble(args[1]);
           }
           catch(Exception e)
           {
               System.out.println(\"Please run program properly. with argument money bet\");
               return;
           }
       }
       else
       {
           System.out.println(\"Please run program properly. with argument money bet\");
           return;
       }
      
       money = passLineBet(money, bet);
       System.out.println(\"You now have: $\" + money);
   }
}

 Part 2 The question in this part of the assignment will be graded. Question 1: Craps (100 points) dice rolls. The goal this question is Craps is a dice game wh
 Part 2 The question in this part of the assignment will be graded. Question 1: Craps (100 points) dice rolls. The goal this question is Craps is a dice game wh
 Part 2 The question in this part of the assignment will be graded. Question 1: Craps (100 points) dice rolls. The goal this question is Craps is a dice game wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site