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

Exercise 6.17 JHTP: (Dice Rolling) Write an application to simulate the rolling

ID: 3850429 • Letter: E

Question

Exercise 6.17 JHTP: (Dice Rolling) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the clause will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent. Figure 6.21 shows the 36 possible combinations of the two die. Your application should roll the dice 36,000 times. Use a one-dimensional array to tally the number of times each possible sum appears. Display the results in a tabular format.

Must be in java, and preferebly work in netbeans. Thanks!

Explanation / Answer

package chegg;

import java.util.Random;

public class DiceRolling {
  
   //DiceRollingResult method
   int DiceRollingResult()
   {
       //object of class Random
       Random rn = new Random();
       int diceResult = rn.nextInt(6) + 1;
       return diceResult;
      
   }
  
   public static void main(String[] args)
   {
       DiceRolling dr=new DiceRolling();
       int i,result1 = 0,result2 = 0;
       int array[]=new int[3600];
      
       System.out.println("---------------Table Result--------------------------");
       // SUM(First DICERoll + Second DICERoll );
       System.out.println("SUM(First DICERoll + Second DICERoll )");
       /*Our application should roll the dice 36,000 times. Used a one-dimensional array to tally the number of times each possible sum appears*/
       for(i=0; i <3600 ; i++)
       {
           result1=dr.DiceRollingResult();
           result2=dr.DiceRollingResult();
           array[i]=result1+result2;
          
           //System.out.println(i+1 +": "+array[i]);
           System.out.println(array[i]);
          
       }      
  
      
   }//end of main method
  

}//end of class

=========================

Output sample

---------------Table Result--------------------------
SUM(First DICERoll + Second DICERoll )
6
8
6
6
11
10
10
6
4
8
6
12
6
6
10
6
7
3
5
6
2
3
5
1

.

.

.

.

.

.

.

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

I have posted few of output sample because due to limitation of this application "Answer cannot be longer than 65,000 characters"

If you have any query, please feel free to ask.

Thanks a lot.

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