Ask Question
13 February, 07:00

Create a new Die object. (Refer to Die. html for documentation.) Create a loop that will iterate at least 100 times. In the loop body:Roll the die. (Don't create a new object, just roll it again.) Based on the result of the roll, increment the corresponding cell of your array.

+5
Answers (1)
  1. 13 February, 08:05
    0
    Java code is given below

    Explanation:

    import java. util. Random;

    class Die{

    private int sides;

    public Die () {

    sides = 6;

    }

    public Die (int s) {

    sides = s;

    }

    public int Roll () {

    Random r = new Random ();

    return r. nextInt (6) + 1;

    }

    }

    class DieRoll{

    public static void main (String[] args) {

    Die die = new Die ();

    int arr[] = new int[6];

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

    arr[i] = 0;

    for (int i=0; i<100; i++) {

    int r = die. Roll ();

    arr[r-1]++;

    }

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

    System. out. println ((i+1) + " was rolled "+arr[i]+" times.");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a new Die object. (Refer to Die. html for documentation.) Create a loop that will iterate at least 100 times. In the loop body:Roll ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers