Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Practice using class methods 2. Practice using class variables 3. Practice object-oriented programming 2 Tasks 1. Create a Java project called DiceRoll. 2. Create

1. Practice using class methods
2. Practice using class variables
3. Practice object-oriented programming
2 Tasks
1. Create a Java project called DiceRoll.
2. Create a class inside your project called Dice.
3. Create a class inside your project called Roll.
4. Create a class inside your project called Main.
5. Add the following two attributes to your Dice class :
(a) private int value
(b) private int sides
6. Modify the two attributes so that they are initialized to have value 1. 7. Add the following methods to your Dice class :
/**
* Assigns s to the sides attribute, to denote the
* number of sides of the die
*/
public void setSides(int s){
}
/**
* Returns the current value of the die
*/
public int getValue(){
}
/**
* Assigns to the value attribute a random integer
* from 1 to sides
8. 9.
10.
11.
*/
public void roll(){
}
Modify the functions above to adhere to their descriptions. In your Roll class, add the following attributes :
(a) private Dice dieOne
(b) private Dice dieTwo
In the Roll class, create a default constructor that initializes the two Dice members to six-
sided dice.
(a) Hint : you will have to use the setSides(int) function for the Dice since sides is a
private attribute !
Add the following methods to the Roll class :
/**
* Re-randomizes each of the member Dice objects
*/
public void roll(){
}
/**
* Returns the sum of the values of the two Dice objects
*/
public int getTotal(){
}
Modify the above functions to function as described
In the Roll class, add a non-default constructor which takes two int arguments and uses
them to set the number of sides to the Dice member objects. Add a main function to the Main class that
(a) Creates two objects of type DiceRoll
i. For the first, construct it with the default constructor.
ii. For the second, use the non-default constructor to specify a pair of dice that has one 8-sided and one 10-sided.
(b) Re-rolls each pair of dice until their totals are the same. (c) Counts the number of

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

Have you been notified by the claims department of your rights?

Answered: 1 week ago

Question

Contact information for the American Management Association

Answered: 1 week ago

Question

How do proposal writers use an RFP? [LO-7]

Answered: 1 week ago