Menu

Modify Class Die Presented Class Include Another Instance Data String Called Color Represe Q43859603

Modify the class Die presented in class to include anotherinstance data (String), called color, to represent the color of adie.

Add a getter/setter for this data and modify the toString methodto return color as well.

Modify the driver program to create 2 dice (one red, one blue)with random face values.

The program should display the dice information as well ascreate another die with color to be the combination of the two dicecolors (eg. red_and_blue) and face value to be the integer averageof the faces of the two dice.

die.java

import java.util.Scanner;

public class Die
{
   private int faceValue;
  
   public Die()
   {
faceValue=(int)(Math.random()*6)+1;
roll();
}
   public Die(int value)
   {
faceValue=value;
   }

   public int getFaceValue()
   {
return faceValue;
   }
  
   public void setFaceValue(int value)
   {
faceValue=value;
   }
  
   public void roll()
   {
faceValue=(int)(Math.random()*6)+1;
   }

   public String toString()
   {
return “Die with face: “+faceValue;
}
}

Expert Answer


Answer to Modify the class Die presented in class to include another instance data (String), called color, to represent the color …

OR