Login to class.mimir.io. Open Lab2: CrapsPlayer project. Instructions are given below for reference.
In the textbook (and slides) there is a Case Study for Playing the Game Craps. Remember the rules of the game are as follows:
◦You roll two dice.
◦Each die has six faces, which contain 1, 2, 3, 4, 5 and 6 spots, respectively.
◦Roll two dice and calculate the sum of the spots...
If the sum is 7 or 11 on the first throw, you win.
If the sum is 2, 3 or 12 on the first throw (called “craps”), you lose (i.e., the “house” wins).
If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, that sum becomes your “point.”
To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value). You lose by rolling a 7 before making your point.
In order to make your CrapsPlayer class work properly for Mimir, we all need to seed our Random number generator with the same seed. The starter code defines a constant SEED=40 and instantiates the randomNumbers
generator for you. This ensures that the pseudo Random number generator always produces the same sequence of generated numbers. It's the only way to match output. Use the same singleton randomNumbers
generator [that is declared for you] to roll the dice and to select a chatter statement.
The starter code has the randomNumbers
singleton, constants for the dice sums such as SNAKE_EYES
that immediately WIN or LOSE the game and most of the code that was given in the case study. Some code has been removed and will have to be replaced with the correct code given the changes that we are making. There are comments with instructions in them that begin with TODO:. Instructions follow.
Follow all instructions and remember to use comments to document methods and blocks of code. Use consistent indentation. I will be giving a style grade manually that may be worth up to 30% of the lab grade.
- Modify the Craps program of FIgure 5.8 in the textbook (Figure 6.8 in the slides) to allow wagering and convert from static methods to instance methods. Call it CrapsPlayer and start with the starter code.
- Modify the class to have two instance variables: bankBalance and wager. Add getter and setter methods for the instance variables.
- Create two constructors for the CrapsPlayer class,
Have the default constructor initialize the bankBalance to 1000.00 dollars and the wager to 100.00.
- Modify the play method to be an instance method. Then add the logic that handles the wager at the end.
WON
, then add the wager to the bankBalance.LOST
, then subtract the wager from the bankBalance.- Add another overloaded instance method play() that takes a double wager parameter. Set the wager and play.
- Add another method called chatter() that uses the randomNumbers
generator to display one of the following chatter lines randomly (assume generated numbers 0-4):
Prompt the player to enter a wager. Check the wager and make sure that it is less than or equal to the bank balance and that the wager is not negative. If the wager is valid, start a round of play. If not, exit the game.
If the bank balance is 0, print "Sorry, You busted!" If there is still bank balance left, print a chatter message and play again.
Current balance is $1000.00
Enter wager (-1 to quit):
100
Player rolled 5 + 2 = 7
Player wins
You're up big. Now's the time to cash in your chips!
Current balance is $1100.00
Enter wager (-1 to quit):
100
Player rolled 6 + 3 = 9
Point is 9
Player rolled 1 + 2 = 3
Player rolled 4 + 4 = 8
Player rolled 4 + 1 = 5
Player rolled 6 + 3 = 9
Player wins
Oh, you're going for broke huh?
Current balance is $1200.00
Enter wager (-1 to quit):
1300
You don't have enough money!
Current balance is $1200.00
Enter wager (-1 to quit):
100
Player rolled 4 + 3 = 7
Player wins
You're way too lucky!
Current balance is $1300.00
Enter wager (-1 to quit):
100
Player rolled 1 + 5 = 6
Point is 6
Player rolled 4 + 3 = 7
Player loses
I'm betting all my money on you.
Current balance is $1200.00
Enter wager (-1 to quit):
100
Player rolled 2 + 5 = 7
Player wins
I'm betting all my mon.ey on you.
Current balance is $1300.00
Enter wager (-1 to quit): 100
Player rolled 6 + 4 = 10
Point is 10
Player rolled 4 + 4 = 8
Player rolled 4 + 1 = 5
Player rolled 6 + 4 = 10
Player wins
Oh, you're going for broke huh?
Current balance is $1400.00
Enter wager (-1 to quit):
100
Player rolled 3 + 6 = 9
Point is 9
Player rolled 1 + 2 = 3
Player rolled 2 + 1 = 3
Player rolled 4 + 5 = 9
Player wins
I'm betting all my money on you.
Current balance is $1500.00
Enter wager (-1 to quit):
1500
Player rolled 2 + 1 = 3
Player loses
Sorry. You busted!