Difference between revisions of "Roulette"
m (Removed <pre> tags from SolutionCode.) |
m (Fixed photo) |
||
Line 68: | Line 68: | ||
|SideSection= | |SideSection= | ||
− | [[Image:Wiki_trays01.jpg|center]] | + | [[Image:Wiki_trays01.jpg|center]]<BR> |
− | <BR> | + | |
|Solution=First, analyze what you need to import. It tells you to generate random numbers. You will need to import Math class which is in java.lang. Also, you will need swing for printing out the money using JOptionPane.<br/> | |Solution=First, analyze what you need to import. It tells you to generate random numbers. You will need to import Math class which is in java.lang. Also, you will need swing for printing out the money using JOptionPane.<br/> |
Revision as of 14:24, 9 April 2010
Back to the Program-A-Day homepage
ProblemPlease read the following carefully, and write a complete program Roulette that prints out total gained from player. |
Mid-term Review | |
---|---|---|
SolutionFirst, analyze what you need to import. It tells you to generate random numbers. You will need to import Math class which is in java.lang. Also, you will need swing for printing out the money using JOptionPane. import java.lang.*; import javax.swing.*;
int money = 100;
for(int i=0; i<20; i++) { double probability is 0.2 }
for(int j=0; j<6, j++) { }
double probability = Math.random();
int random = (int)(Math.random() * 99)
if(probability > chance) { if(j % 2 == 0) money -= 50 else money += 50 } This pseudo-code means if there was a gun fire, check whose turn it is. money = money - 50;
if(j < 4) probability += 0.1 else probability += 0.25
JOptionPane.showMessageDialog(null, money);
| ||
Code |