Bottle Cap Project: Random Numbers
843789Mar 10 2010 — edited Mar 11 2010Assignment 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!");
}
}