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
Step: 1
Heres the complete code with the requested methods and a test application MyMethodsjava Java public ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started