Question: Explain each statement with notes import java.util.ArrayList; import java.util.Random; public class Main { public static void main(String[] args) { Die[] dice = new Die[5]; for

 Explain each statement with notes import java.util.ArrayList; import java.util.Random; public class Main { public static void main(String[] args) { Die[] dice = new Die[5]; for (int i = 0; i < dice.length; i++) { dice[i] = new Die(); } int kindOf3 = 0; int kindOf4 = 0; int kindOf5 = 0; for (int i = 0; i < 100000; i++) { ArrayList num = new ArrayList<>(); int count = 0; for (int j = 0; j < dice.length; j++) { int n = dice[j].rollDie(); if (num.contains(n)){ count++; } num.add(n); } if (count==3) kindOf3++; if (count==4) kindOf4++; if (count==5) kindOf5++; } System.out.println("In 100,000 rolls, you rolled 3 of a kind "+kindOf3+" times, 4 of a kind "+kindOf4+" times, and 5 of a kind "+kindOf5+" times."); } } class Die { private int number; public Die() { } public int rollDie() { Random random = new Random(); return random.nextInt(6) + 1; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!