Probability game
Author |
Message |
r.m_spy
|
Posted: Fri Apr 23, 2010 5:08 pm Post subject: Probability game |
|
|
code: |
import java.util.Random;
class probability
{
public static void main(String[]args)
{
random();
}
public static void random()
{
Random dice = new Random();
int num,num2,num3,num4,score,count;
score=0;
count=0;
while(score<100)
{
num =1+dice.nextInt(6);
num2=1+dice.nextInt(6);
num3=1+dice.nextInt(6);
num4=1+dice.nextInt(6);
System.out.println("Your numbers are "+num+","+num2+","+num3+","+num4);
if (num==num2 && num2==num3 && num3==num4)
{
System.out.println("You got four of a kind.(Worth 100 points.) YOU WIN");
score=score+100;
}
else if(num==num2-1 && num2==num3-1 && num3==num4-1 || num==num2+1 && num2==num3+1 && num3==num4+1)
{
System.out.println("You got a royal flush. (Worth 75 points.");
score=score+75;
}
else if (num==num2 && num2==num3 || num==num2 && num2==num4 || num==num3 && num3==num4 || num2==num3 && num3==num4)
{
System.out.println("You got three of a kind.(Worth 50 points.)");
score=score+50;
}
else if(num==num2+1 && num2==num3+1 || num==num2+1 && num2==num4+1 || num==num3+1 && num3==num4+1 || num2==num3+1 && num3==num4+1)
{
System.out.println("You got a flush. (Worth 40 points.)");
score=score+40;
}
else if (num==num2 || num==num3 || num==num4 || num2==num3 || num2==num4 || num3==num4)
{
System.out.println("You got two of a kind.(Worth 25 points.)");
score=score+25;
}
count++;
}
System.out.println("It took you "+count+" rolls to get 100 points");
}
}
|
Description: |
|
Download |
Filename: |
probability.java |
Filesize: |
1.4 KB |
Downloaded: |
249 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
r.m_spy
|
Posted: Fri Apr 23, 2010 5:09 pm Post subject: RE:Probability game |
|
|
ps: In.getString is a code I use to get input. you can replace with Jav.util.scanner.*;
if you dont have it
|
|
|
|
|
|
r.m_spy
|
Posted: Fri Apr 23, 2010 5:11 pm Post subject: RE:Probability game |
|
|
ps: In.getString is a code I use to get input. you can replace with Jav.util.scanner.*;
if you dont have it
|
|
|
|
|
|
Insectoid
|
Posted: Fri Apr 23, 2010 5:18 pm Post subject: RE:Probability game |
|
|
If you have several small programs, put them all in the same thread. I also advise against posting such small programs as this. Trust me, we've seen every assignment you'll ever do in high school a dozen and a half times. Post your final project when it's done, or something new and creative.
Anyway, I suggest you look into arrays. Will save you some lines.
|
|
|
|
|
|
|
|