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

Please tell me why I am getting zero on my results for double sixes..It is somet

ID: 3563914 • Letter: P

Question

Please tell me why I am getting zero on my results for double sixes..It is something I did wrong with the loop..Thank You

import java.util.Random;        //to use the random number generator
public class DiceSimulation
{
    public static void main(String[] args)
        {
           Random generator = new Random();
           final int NUMBER = 10000; //the number of times to
    //roll the dice
  
  
  
    int count = 0; // number of times the dice were
    // rolled
    int snakeEyes = 0; // number of times snake eyes
    // rolled
    int twos = 0; // number of times double two is
    // rolled
    int threes = 0; // number of times double three
    // is rolled
    int fours = 0; // number of times double four
    // is rolled
    int fives = 0; // number of times double
    // five is rolled
    int sixes = 0; // number of times double six is
    // rolled

         
         
    for(count = 0; count <= 10000; count++)
    {
           int die1Value = generator.nextInt(6); //random number 0..5
           //die1Value ++;
           System.out.println("Die one value is " + die1Value);// number of spots on the first
     
           int die2Value = generator.nextInt(6);
           //die2Value ++;
           System.out.println("Die two value is " + die2Value);// number of spots on the second die
   
    if (die1Value == die2Value)
        if (die1Value == 1)
            ++snakeEyes;
            else if (die1Value == 2)
            ++twos;
            else if (die1Value == 3)
            ++threes;
            else if (die1Value == 4)
            ++fours;
            else if (die1Value == 5)
            ++fives;
            else if (die1Value == 6)
            ++sixes;
            ++count;
        }
  
        System.out.println ("You rolled snake eyes " +
    snakeEyes + " out of " + count + " rolls.");
    System.out.println ("You rolled double twos " + twos +
    " out of " + count + " rolls.");
    System.out.println ("You rolled double threes " +
    threes + " out of " + count + " rolls.");
    System.out.println ("You rolled double fours " + fours
    + " out of " + count + " rolls.");
    System.out.println ("You rolled double fives " + fives
    + " out of " + count + " rolls.");
    System.out.println ("You rolled double sixes " + sixes
    + " out of " + count + " rolls.");
}  
}
  
     
              

Explanation / Answer

import java.util.Random;        //to use the random number generator
public class DiceSimulation
{
    public static void main(String[] args)
        {
           Random generator = new Random();
           final int NUMBER = 10000; //the number of times to
    //roll the dice
    int count = 0; // number of times the dice were
    // rolled
    int snakeEyes = 0; // number of times snake eyes
    // rolled
    int twos = 0; // number of times double two is
    // rolled
    int threes = 0; // number of times double three
    // is rolled
    int fours = 0; // number of times double four
    // is rolled
    int fives = 0; // number of times double
    // five is rolled
    int sixes = 0; // number of times double six is
    // rolled
    for(count = 0; count <= 10000; count++)
    {
           // DIE VALUE SHOULD BE between 1 and 6 so please add 1 in below line.
           int die1Value = generator.nextInt(6)+1; //random number 0..5
           //die1Value ++;
           System.out.println("Die one value is " + die1Value);// number of spots on the first
           // DIE VALUE SHOULD BE between 1 and 6 so please add 1 in below line.
           int die2Value = generator.nextInt(6)+1;
           //die2Value ++;
           System.out.println("Die two value is " + die2Value);// number of spots on the second die
    if (die1Value == die2Value)
        if (die1Value == 1)
            ++snakeEyes;
            else if (die1Value == 2)
            ++twos;
            else if (die1Value == 3)
            ++threes;
            else if (die1Value == 4)
            ++fours;
            else if (die1Value == 5)
            ++fives;
            else if (die1Value == 6)
            ++sixes;
            ++count;
        }
        System.out.println ("You rolled snake eyes " +
    snakeEyes + " out of " + count + " rolls.");
    System.out.println ("You rolled double twos " + twos +
    " out of " + count + " rolls.");
    System.out.println ("You rolled double threes " +
    threes + " out of " + count + " rolls.");
    System.out.println ("You rolled double fours " + fours
    + " out of " + count + " rolls.");
    System.out.println ("You rolled double fives " + fives
    + " out of " + count + " rolls.");
    System.out.println ("You rolled double sixes " + sixes
    + " out of " + count + " rolls.");
}
}