Before we jump into the details of the assignment, I’d like to share my solution for the Texas Holdem Poker assignment.
This was a very complex assignment and it even took about 4 hours of video to explain the solution in its entirety. This video is available for members of my video tutorials.
High Stakes Roulette – Rules
Now let’s get on with the next Java practice assignment! If you’re not familiar with the game of roulette, it’s fairly simple to understand. Basically it’s a game of selecting a random number between 1 and 36; this is done by spinning a roulette wheel while a ball bounces around before finally landing on one number. The numbers 1 through 36 have alternating colors (black and red), and this allows for certain betting to occur.
Before each spin of the roulette wheel, you are allowed to bet on a wide variety of things, but for this assignment you only need to concern yourself with the fact that you can bet on either black or red.
If you bet on red, and the roulette ball lands on red, then you win twice the amount that you bet (eg. if you bet $10 on red, and the ball lands on red, you will win $20)! If you bet on red, and the ball lands on black, then you lose your entire bet.
Note: There are also two “green” numbers (0 and 00), if the ball lands on one of these two numbers, then you will lose your bet regardless on which color (red or black) you had bet on.
Okay, now that you understand the pertinent aspects of roulette let’s talk about what this assignment will involve.
I’m interested in cheating the system and guaranteeing that I’ll win money at roulette. Here’s how I think it can be done:
If you consistently bet on one color (either red or black), you’ll eventually win right? The trick will be to keep doubling your bet until you actually win. So I want to know how much money you need to have in order to guarantee that you’ll be able to win $10 for each “cycle” of continuous betting.
Here’s an example of what I mean:
- Choose a color to bet on and STICK with it for the entire “cycle” of betting
- Place your bet of $10 and spin the wheel
- If you lose, bet twice the amount of your last bet
- Repeat step 3 until you win then go to step 5
- If you win, record the amount you needed to bet in order to win
So in the end, what I’m interested in knowing is the MAXIMUM amount of money needed to guarantee that out of 10,000 spins of the roulette wheel, I’ll win my $10 every time.
What you’ll need to implement
In a word: everything!
I think if you’ve come this far in your Java programming journey, you should be able to create this assignment from scratch. I won’t leave you completely high and dry though, here are the basic aspects you’ll need to implement:
- Roulette Wheel (for spinning)
- Roulette Number (represents a number with a color)
- Random Number Generator (used to generate a random number from 1 to 38; includes values for 0 and 00)
- You may want to implement an Enum to represent the Colors (up to you)
- Test class or Runnable class
Remember: the point of the assignment is to determine how much money you’ll need to have in your pocket to guarantee that you’ll always win $10 at the game of roulette by consistently betting on the same color until you win.