Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Bottle Cap Project: Random Numbers

843789Mar 10 2010 — edited Mar 11 2010
Assignment Write a program that uses the Monte Carlo sampling method to estimate the average number of bottles of Boost someone would have to drink to win a prize. There is one in five chance that a bottle cap will have a prize.

I cant get the program to keep generating numbers and im having some trouble with the count.

import java.util.Scanner;
public class BottleCap
{
public static void main(String[] args)
{
int win = 0;
int lose = 0;
int counter = 1;
double randNum = 0.0;
Scanner in = new Scanner(System.in);

System.out.println("How many e-Boost will you have to drink?");

randNum = Math.random();

while(randNum < .8);
{
System.out.print(counter "\t" randNum);

if(randNum < .8)
{
lose++;
System.out.println("\t lose");
}
else
{
win++;
System.out.println("\t win");
}
counter++;
}
System.out.println();
System.out.println("It took " lose " e-Boost!");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 8 2010
Added on Mar 10 2010
5 comments
914 views