Need some assistance please
/************************************************** ************
Not sure if my second constructor is working properly please help. It is intended to be copy and used to sort the die in yahtzee so i could use it for checking 3 of a kind. 4 of a kind. 5 of a kind. Yahtzee. and full house on a different java class.
************************************************** ************/
public class Dice
{
Die [] dice;
Random gen;
/************************************************** ************
The constructor uses a random generator to build each die.
The number of Die objects is passed as a parameter.
@param gen The random generator
@param num The number of die objects
************************************************** ************/
public Dice(Random gen, int num)
{
this.gen = gen;
dice = new Die[num];
for (int ii = 0; ii < dice.length; ii++)
{
dice[ii] = new Die(gen);
}
}
/************************************************** ************
This copy constructor returns an identical set of dice to
the parameter. This is used to create a set of dice whose
order can be changed from the original.You should use the
Die constructor that creates a die with the same face value
as the original for each of the Die in the set.
@param dice The Dice object to copy
************************************************** ************/
public Dice(Dice dice)
{
for(int ii = 0; ii < dice.getSize(); ii++)
{
this.dice[ii] = new Die(new Random());
}
// check me
}
Re: Need some assistance please
Quote:
Originally Posted by
JavaPhish
/************************************************** ************
Not sure if my second constructor is working properly please help. It is intended to be copy and used to sort the die in yahtzee so i could use it for checking 3 of a kind. 4 of a kind. 5 of a kind. Yahtzee. and full house on a different java class.
************************************************** ************/
public class Dice
{
Die [] dice;
Random gen;
/************************************************** ************
The constructor uses a random generator to build each die.
The number of Die objects is passed as a parameter.
@param gen The random generator
@param num The number of die objects
************************************************** ************/
public Dice(Random gen, int num)
{
this.gen = gen;
dice = new Die[num];
for (int ii = 0; ii < dice.length; ii++)
{
dice[ii] = new Die(gen);
}
}
/************************************************** ************
This copy constructor returns an identical set of dice to
the parameter. This is used to create a set of dice whose
order can be changed from the original.You should use the
Die constructor that creates a die with the same face value
as the original for each of the Die in the set.
@param dice The Dice object to copy
************************************************** ************/
public Dice(Dice dice)
{
for(int ii = 0; ii < dice.getSize(); ii++)
{
this.dice[ii] = new Die(new Random());
}
// check me
}
Does this code compile?
If yes, what are the exceptions thrown by JVM?
If no, what are the errors spit out by compiler?
And Welcome to Java Programming Forums. Read the forums Rules too. Enclose your code in code tags.
Re: Need some assistance please
The code does compile with no exceptions.
Re: Need some assistance please
Quote:
Originally Posted by
JavaPhish
The code does compile with no exceptions.
I'm not really sure what your question is then? If you want help, you'll have to ask a specific technical question and provide an SSCCE that demonstrates what's going on.