Difference between revisions of "Week 6"
From CompSciWiki
Line 3: | Line 3: | ||
|ProblemName=Roulett | |ProblemName=Roulett | ||
− | |Problem= | + | |Problem=Write a complete program Roulett that prints out total gained from player.<br> |
− | Each game will be running for 6 turns. Player will take the first turn | + | Each game will be running for 6 turns. Player will take the first turn <br> |
− | followed by the opponent. You need to generate a double random number | + | followed by the opponent. You need to generate a double random number <br> |
− | each time that will represent the chance of getting shot. | + | each time that will represent the chance of getting shot. <br> |
− | If the chance is smaller than the probability, then the bullet is fired. | + | If the chance is smaller than the probability, then the bullet is fired.<br> |
− | First turn, the probability starts at 0.2. After the first turn, you have to increase the probability. | + | First turn, the probability starts at 0.2. After the first turn, you have to increase the probability. <br> |
− | It will increase 0.1 for first four times, then, it will increase 0.25 for the 5th and the 6th time. | + | It will increase 0.1 for first four times, then, it will increase 0.25 for the 5th and the 6th time.<br> |
− | If the player wins the player gets $ 50 dollars, otherwise the player loses $ 50 dollars. | + | If the player wins the player gets $ 50 dollars, otherwise the player loses $ 50 dollars.<br> |
− | The starting money of the player will be $ 100 dollars. | + | The starting money of the player will be $ 100 dollars.<br> |
− | + | <br> | |
− | Example. 1st(player, 0.2), 2nd(opponent, 0.3), 3rd(player, 0.4), 4th(opponent, 0.5), 5th(player, 0.75), 6th(opponent, 1.0) | + | Example. 1st(player, 0.2), 2nd(opponent, 0.3), 3rd(player, 0.4), 4th(opponent, 0.5), 5th(player, 0.75), 6th(opponent, 1.0)<br> |
− | + | <br> | |
− | Print out the output (money of the player) using JOPtionPane. | + | Print out the output (money of the player) using JOPtionPane.<br> |
− | < | + | |
|SolutionCode=<pre>import java.lang.Math.*; | |SolutionCode=<pre>import java.lang.Math.*; | ||
import javax.swing.*; | import javax.swing.*; |
Revision as of 14:30, 5 April 2010
Back to the Program-A-Day homepage
ProblemWrite a complete program Roulett that prints out total gained from player. Each game will be running for 6 turns. Player will take the first turn |
...by students
An image or By Students section | |
---|---|---|
SolutionThe solution... | ||
Code |