The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
My professor has provided this below:
We are instructed the following:
4. Implement a version of the Die class that automatically rolls the die when created
a. Class name is DieVer2
b. The constructor is: public DieVer2()
c. The public methods are public void roll() and public int getNumber()
5. Implement a many-sided die class that takes the number of sides as a constructor parameter and whether to roll in the constructor.
a. Class name is ManySidedDi e
b. The constructor is: public ManySidedDie(int sides, boolean roll)
c. The public methods are public void roll() and public int getNumber()
package week04;
import java.util.Random;
/**
* This class simulates a dice
* It utilizes the Random class to generate a random number
*
* @author Ashlee
*
*/
public class Die
{
// Constructor
public Die()
{
random = new Random();
number = NO_NUMBER;
}
// Rolls the dice
public void roll()
{
number = random.nextInt(MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER;
}
// Returns the number on this dice
public int getNumber()
{
return number;
}
// Data Members
// the largest number on a dice
private static final int MAX_NUMBER = 6;
// the smallest number on a dice
private static final int MIN_NUMBER = 1;
// to represent a dice that is not yet rolled
private static final int NO_NUMBER = 0;
private int number;
private Random random;
}
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly