Professional Documents
Culture Documents
Be sure to include any pre and post conditions. Comment ALL classes thoroughly
and meet ALL programming expectations.
1.
2.
Create a main class BoxCars with a class called Die, which counts the
number of box cars (two sixes) that occur. The
constructor should set the die up to be sitting on
snake eyes to begin the rolling (each die starts at
1). The Die class should have the following
methods:
a. rollIt (this methods simulates and gets the new random number and
sets the face)
b. isBoxCar (this methods returns true if the die is a 6 and false
otherwise)
The main class should roll the two dice 1000 times. When done it should
print out the number of times, the boxcars occurred.
3.
Create a main class PlayPig that uses a class called PlayerDie. In this game,
the user competes against the computer. On each turn, the player rolls a
pair of dice and adds up his or her points. Whoever reaches 100 points first,
wins. If a player rolls a 1, he or she loses all points for that round and the
dice go to the other player. If a player rolls two 1s in a
turn, he loses all points in the entire game and loses
control of the dice. The player may voluntarily turn over
the dice after each roll. So the player must decide to
either roll again (be a pig) and risk losing point, or give
up the dice, possibly letting the other player win. Set up
the computer player so that it always gives up the dice after getting 20 or
more points in a round.
a. What will you need to know about each player? What do you need to
set-up in your constructor?
b. You will need to have the following methods
i. getTotalPoints (returns the totalPoints)
ii. getCurrentPoints (returns the currentPoints)
iii. addTotalPoints(take the current points when the person
choose to pass and add them to the totalyou
will also need to reset your currentPoints to 0)
iv. rollDice (this will generate the dice)
v. addPoints (this will add the points to the
current points)
vi. resetCurrent (this will clear the current points
on a pass or snakeEyes)
vii. snakeEye (checks if a 1 was rolled and clears the
currentPoints)
viii. doubleSnakeEyes (checks if 2 1s were rolled and clears the
currentPoints and the totalPoints)
ix. toString (which will print the users totalPoints and
currentPoints along with the computers totalpoints and
currentpoints)
x. You may choose to add any other methods that you deem
necessary
The main class should print running totals out for the user to see. What do
you need in your main class??
Hint
loop until the points are reached
loop for the human player