Design a Java Die program which can show following results D

Design a Java Die program which can show following results:

Die one: 6, Die Two: 4

Die one: 4, Die Two: 1

Die one: 1, Die Two: 2

Die one: 2, Die Two: 6

Die one: 4, Die Two: 4

Die one: 3, Die Two: 1

Die one: 1, Die Two: 5

Die one: 1, Die Two: 1

Occurrence counts for rolling doubles for each face value: Doubles occurred 2 times

Doubles of 1: 1

Doubles of 2: 0

Doubles of 3: 0

Doubles of 4: 1

Doubles of 5: 0

Doubles of 6: 0

Solution

TwoDiceTest.java

import java.util.Random;
import java.util.Scanner;


public class TwoDiceTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print(\"How many times should the dice be rolled? \");
       int n = scan.nextInt();
       int count[] = {0,0,0,0,0,0};
       int doubleCount = 0;
       Random r = new Random();
       for(int i=0; i<n;i++){
           int die1 = r.nextInt(6)+1;
           int die2 = r.nextInt(6)+1;
          
           System.out.println(\"Die one: \"+die1+\", Die Two: \"+die2);
           if(die1 == die2){
           count[die1-1]++;
           doubleCount++;
           }
       }
       System.out.println(\"Occurrence counts for rolling doubles for each face value: Doubles occurred \"+doubleCount+\" times\");
       for(int i=0; i<count.length; i++){
           System.out.println(\"Doubles of \"+(i+1)+\": \"+count[i]);
       }

   }

}

Output:

How many times should the dice be rolled? 8
Die one: 5, Die Two: 6
Die one: 4, Die Two: 4
Die one: 6, Die Two: 1
Die one: 4, Die Two: 3
Die one: 6, Die Two: 3
Die one: 2, Die Two: 5
Die one: 1, Die Two: 1
Die one: 1, Die Two: 1
Occurrence counts for rolling doubles for each face value: Doubles occurred 3 times
Doubles of 1: 2
Doubles of 2: 0
Doubles of 3: 0
Doubles of 4: 1
Doubles of 5: 0
Doubles of 6: 0

Design a Java Die program which can show following results: Die one: 6, Die Two: 4 Die one: 4, Die Two: 1 Die one: 1, Die Two: 2 Die one: 2, Die Two: 6 Die one:
Design a Java Die program which can show following results: Die one: 6, Die Two: 4 Die one: 4, Die Two: 1 Die one: 1, Die Two: 2 Die one: 2, Die Two: 6 Die one:

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site