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

Simple java assignment. please comment your code so I know what you did. thanks

ID: 3694245 • Letter: S

Question

Simple java assignment. please comment your code so I know what you did. thanks

How the game is played. Two six sided dice are rolled. First roll in a round called "Come out roll" A come out of 7 or 11 automatically wins. A roll of 2, 3, or 12 automatically loses. Any other number becomes the point. Player keeps rolling until either he rolls the point (wins) or rolls 7 (loses) Your simulation should run 100,000 times and print out the number of wins by the player, and the number of wins by the house. One major part of this project is good decomposition of the problem into methods. Think about this before you begin. Be sure to use good names for your methods, and document what each method does (but not how it does it)

Explanation / Answer

import java.io.*;

import java.util.Random;

public class CrapsGame

{

      public static void main(String[] args)

{

//declaration and initialization of variables

    public static int gameswon = 0;

    public static int gameslost = 0;

    public static int max = 6;

    public static int min = 1;

     int diceValue,diceValue2,point;

     //simulating 10000 times

    for ( int i = 0 ; i < 10000; i++)

    {

            diceValue = diceSimulator(max,min );

            System.out.println("original dicevalue is " + diceValue);

//based dicevalue wewill count losses and winnings

     switch (diceValue)

    {

    case 7:

    case 11:

            gameswon++;

        break;

    case 2:

    case 3:

    case 12:

            gameslost++;

        break;

    default:

        point = diceValue;

          do

    {

            System.out.println("point " + point );

            diceValue2 = diceSimulator(max,min);

            if (diceValue2 == point)

                {

System.out.println("point is rolled");

                gameswon++;

                 }

            else if(diceValue2 == 7)

                {

                System.out.println("7 is rolled game loss");

                gameslost++;

               }

            else

            {

                System.out.println("diceValue2 is " + diceValue2);

            }

             

          }

        while ((diceValue2 != 7) && (diceValue2 != point) );

         

         break;

    }      

    }  

    System.out.println("games won: " + gameswon);

    System.out.println("games lost: " + gameslost);

    System.out.printf("Probability of winning:%.2f " , (double) gameswon/ (gameswon + gameslost));

}

  //using this function found random values between 1 to 6 for two dices       

    public static int diceSimulator(int nmax,int nmin)

    {

          int randomn1 = (int) ( nmin + Math.random() * ((nmax - nmin + 1) ));

          int randomn2 = (int) (nmin + Math.random() * ((nmax - nmin + 1 ))) ;

          int random = randomn1 + randomn2;

           return random;

          }

    }

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