Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

More Books

Students also viewed these Programming questions

Question

What activities do you enjoy when you are not working?

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

Discuss about training and development in India?

Answered: 1 week ago

Question

Explain the various techniques of training and development.

Answered: 1 week ago

Question

Explain the various techniques of Management Development.

Answered: 1 week ago

Question

The value of the bond is $ ( Round to the nearest cent. )

Answered: 1 week ago

Question

Show that n 2 is W(nlogn).

Answered: 1 week ago