Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java answer the following: 1. Implement a method diceStats() that takes an integer parameter, num. The method creates a square matrix (2-dim array) of

Using Java answer the following:

1. Implement a method diceStats() that takes an integer parameter, num. The method creates a square matrix (2-dim array) of die objects and rolls them all. The method returns an int array of size 6, containing the number of dice in the matrix for each face value 1-6. For example, if the matrix is of size 2 and dice have the following face values: 2 4 4 5 the method will return 0,1,0,2,1,0 You may use the Die class introduced in class.

2. Write an application that tests this method.

Die.java

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;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago