Program help?
Hey, fellow java programmers.
I've been working on a "Pig" program, which requires a class called "PairofDice" and a "Pig" class.
I've gotten the "PairofDice" down without too much trouble. The driver program shouldn't be too hard to write...but I have NO clue on how to write a "Pig" class!
Basically, I've got two dice. I need a player to be able to roll the dice, and add his/her points. Whoever reaches 100 points first wins. If a player rolls a 1, he/she loses all points. If a player rolls two 1s in one turn, the player loses all points earned so far in the game and loses control of the dice. The player needs to decide to either roll again and risk losing points, or give up the dice, possible letting the other player (the computer) win. I also need to set it up so the player always gives up the dice after getting 20+ points in a round.
publicclass PairOfDice
{
privateint die1;// Number showing on the first die.
privateint die2;// Number showing on the second die.
public PairOfDice()
{
// Constructor. Rolls the dice, so that they initially
// show some random values.
roll();// Call the roll() method to roll the dice.
}
publicvoid roll()
{
// Roll the dice by setting each of the dice to be
// a random number between 1 and 6.
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
}
publicint getDie1()
{
// Return the number showing on the first die.
return die1;
}
publicint getDie2()
{
// Return the number showing on the second die.
return die2;
}
publicint getRoll()
{
// Return the total showing on the two dice.
return (die1 + die2);
}
}// end class PairOfDice
That's my "PairofDice" class. So, my question is this: how should I proceed to write a "Pig" class?
I would really appreciate any help I could get, as this program could either make me fail or pass this semester.
Thank you.
- Max

