Use the given die class for the problems below: public class Die { //attributes private int faceValue;
Question:
Use the given die class for the problems below:
public class Die {
//attributes
private int faceValue; // declare an attribute
//operations
//default constructor
public Die() {
//faceValue = 2;
roll();
}
//roll method
public void roll(){
faceValue = (int)(Math.random()*6)+1;
}
//non-default constructor
public Die(int face){
faceValue = face;
}
//getter
public int getFaceValue(){
return faceValue;
}
//setter
public void setFaceValue(int face){
faceValue = face;
}
public String toString(){
return ""+faceValue;
}
}
(Each problem below is a method in the class MyMethods.java)
1a Implement a method named surface that accepts 3 integer parameters named width, length, and height as user input. It will return the total surface area (6 sides) of the rectangular box it represents. The formula for Surface Area is 2(length * width) + 2(length * height) + 2(height * width)
1b. Implement a method named avgFaceValues that accepts 2 Die objects.Use the given die class above. The method returns the average faceValue of the two die objects. For example, if die1 has face value 4 and die2 has face value 5, the method should return 4.5.
1c.To test methods above,write an application, TestMethods,that will instantiate an instance (object) of the class MyMethods to invoke the methods below. The application should have at least one invocation of each method.
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser