Die class in Java programming

How to Use the Die class ,and  write a method that will use create two Die, roll them 100 times and return the number of times that a total of 7 or 11 is rolled on the two Die.
and her is the Die class

public class Die
{
   private final int MAX = 6;  // maximum face value

   private int faceValue;  // current value showing on the die

 
   public Die()
   {
      faceValue = 1;
   }

   
   public int roll()
   {
      faceValue = (int)(Math.random() * MAX) + 1;

      return faceValue;
   }

   
   public void setFaceValue (int value)
   {
      faceValue = value;
   }

 
   public int getFaceValue()
   {
      return faceValue;
   }

   
   public String toString()
   {
      String result = Integer.toString(faceValue);

      return result;
   }
}

Is it like that

public class RollingDice
{
 
   public static void main (String[] args)
   {
      Die die1, die2;
      int sum;

      die1 = new Die();
      die2 = new Die();
Ansary100Asked:
Who is Participating?
 
b1xml2Commented:
public static void main (String[] args)
   {
      Die die1, die2;
      int sum = 0;
      int value;
        
      die1 = new Die();
      die2 = new Die();
      for (int i=0;i<100;i++)
      {
            value = die1.roll() + die2.roll();
            if (value == 7 || value == 11)
                  sum++;
            
      }
   }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.