Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3011
  • Last Modified:

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();
0
Ansary100
Asked:
Ansary100
1 Solution
 
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now