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

At start of game, a user is given a pot of 100 coins. For every game, the user i

ID: 3665823 • Letter: A

Question

At start of game, a user is given a pot of 100 coins.  For every game, the user is asked how much they want to bet.  This is an integer amount from 0 to their pot value.  The program should check to make sure the bet is in this range and if not, keep re­asking the user for a bet until a correct one is given. (use a while loop for this).       The program will also keep track of the user's total pot.  For each game won, the user gets their bet amount added to their pot.  For each game lost, the user loses the bet amount from their pot.  If their pot goes to zero, then the program should just quit with a message.   The user's pot will be printed after each game so the user knows what he has in the pot.     The program should allow the user to play a full game as many times as they want by asking whether they want to play again.  The input should take either a 'y'/'yes' or an 'n'/'no'.   If the user says 'y' or 'yes', the game should be played again.  Otherwise, the program should terminate.     The rules of the game are as follows: 1.  The user is ask for their bet. 2. Two dice are then rolled. 3. The sum of the two dice are interpreted as follows:      a.  The user wins the game if the dice add up to 11 or 7.      b.  The user loses the game if the dice add up to 2, 3 or 12.      c.   Any other sum is called a 'point'.   4.  If the user gets a 'point', from here on, the dice keeps getting rolled until this 'point' value shows up or a 7 shows up.       a. if a 7 shows up, the user loses.       b. if their point shows up, the user wins. 5.  After winning or losing, check the pot to see if it is zero. If so, quit the program. 6.  If the pot still has coins, the user is ask if they want to play again. If so,       play starts at 1. above.  If not, print out their pot and end the program.        Using Random Number Generator Use the java.util.Random class to pick numbers between 1 and 6 to represent the two dice:         int die1, die2;         Random r = new Random();                   .........................                die1 = r.nextInt(6) + 1;         die2 = r.nextInt(6) + 1;

Explanation / Answer

import java.util.Random;


public class PairOfDice {
       Random r ;
        private int die1;   // Number showing on the first die.
        private int die2;   // Number showing on the second die.
      
        public PairOfDice() {
                // Constructor. Rolls the dice, so that they initially
                // show some random values.
            roll(); // Call the roll() method to roll the dice.
        }
      
        public void roll() {
                // Roll the dice by setting each of the dice to be
                // a random number between 1 and 6.
           r = new Random();
           die1 = r.nextInt(6) + 1;
            die2 = r.nextInt(6) + 1;
        }
      
        public int getTotal() {
              // Return the total showing on the two dice.
           return die1 + die2;
        }
      
     } // end class

-----------------------------------------------------------------------------------


import java.util.Scanner;

public class DiesProgram {

   public static void main(String[] args) {
      
         // An object that will refer to the dice.
         PairOfDice dice;
         int potValue=100;      
         dice = new PairOfDice();        
        boolean isPoint=false;
        Scanner betAmount ;
        int bet=0;
        int diceTotal= dice.getTotal();
        String isContinue ="y";
        Scanner sc= new Scanner(System.in);
        do
         {
           System.out.println(" You have "+potValue +" coins in the pot.");
              if(potValue<=0)
              {
                  System.out.println(" You dont have amount in the pot.");
                  break;
              }
              //if not point then read new value.
              if(!isPoint)
              {
                  System.out.println(" How much you want to bet.");
                  betAmount= new Scanner(System.in);
                  bet= betAmount.nextInt();              
              }
              else
              {
                  //diceTotal=11;
                  System.out.println(" Old Bet is: "+bet );
              }
              dice = new PairOfDice();
              diceTotal= dice.getTotal();
          
              System.out.println(" Dice total: "+ diceTotal);
              switch(diceTotal)
              {
              case 11:
              case 7:
                  if(diceTotal==7 && isPoint)
                  {
                      System.out.println(" You got "+diceTotal +" after point. So you lost the game. ");              
                      potValue=potValue-bet;  
                                        
                  }
                  else
                  {
                      potValue=potValue+bet;
                      System.out.println(" You got "+diceTotal +". You won the game.Current pot value: "+ potValue);                  
                  }
                  isPoint=false;
                  break;
              case 2:
              case 3:
              case 12:
                  if( isPoint)
                  {
                      System.out.println(" You got "+diceTotal +" after point. So you won the game. ");              
                      potValue=potValue+bet;
                      isPoint=false;
                      break;
                  }
                  System.out.println(" You got "+diceTotal +". You lost the game.");
                  potValue=potValue-bet;
              
                  break;
              default:
                  if( isPoint)
                  {
                      System.out.println(" You got "+diceTotal +" after point. So you won the game. ");              
                      potValue=potValue+bet;
                      isPoint=false;
                      break;
                  }
                      isPoint=true;
                  
              }
          
              if(!isPoint)
              {
               System.out.println(" Do you want to continue.(yes/no) (y/n).");              
               isContinue= sc.next();
                  isContinue= isContinue.toString();//.toLowerCase();
                 
              }
              if(potValue<=0)
              {
                  System.out.println(" You dont have amount in the pot.");
                  break;
              }
  
         } while(!isContinue.equals("n") && !isContinue.equals("no"));
    
       
         System.out.println(" Terminating the game.");
       
      }
}

------------------------------------------------------------------------------------

Output:

-----------------------------------
You have 100 coins in the pot.

How much you want to bet.
40

Dice total: 4

You have 100 coins in the pot.

Old Bet is: 40

Dice total: 4

You got 4 after point. So you won the game.

Do you want to continue.(yes/no) (y/n).
y

You have 140 coins in the pot.

How much you want to bet.
90

Dice total: 8

You have 140 coins in the pot.

Old Bet is: 90

Dice total: 5

You got 5 after point. So you won the game.

Do you want to continue.(yes/no) (y/n).
y

You have 230 coins in the pot.

How much you want to bet.
80

Dice total: 7

You got 7. You won the game.Current pot value: 310

Do you want to continue.(yes/no) (y/n).
y

You have 310 coins in the pot.

How much you want to bet.
90

Dice total: 4

You have 310 coins in the pot.

Old Bet is: 90

Dice total: 11

You got 11. You won the game.Current pot value: 400

Do you want to continue.(yes/no) (y/n).
y

You have 400 coins in the pot.

How much you want to bet.
90

Dice total: 10

You have 400 coins in the pot.

Old Bet is: 90

Dice total: 5

You got 5 after point. So you won the game.

Do you want to continue.(yes/no) (y/n).
y

You have 490 coins in the pot.

How much you want to bet.
90

Dice total: 11

You got 11. You won the game.Current pot value: 580

Do you want to continue.(yes/no) (y/n).
y

You have 580 coins in the pot.

How much you want to bet.
80

Dice total: 2

You got 2. You lost the game.

Do you want to continue.(yes/no) (y/n).
y

You have 500 coins in the pot.

How much you want to bet.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote