Question: Use the given die class for the problems below: public class Die { //attributes private int faceValue; // declare an attribute //operations //default constructor public

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the complete code with the requested methods and a test application MyMethodsjava Java public ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!