Hi, I'm working on this project right now which probably shouldn't be that difficult but I'm really confused and lost. The assignment's instructions are: "Write a program that uses the Monte Carlo sampling method to estimate the average number of bottles of e-Boost someone would have to drink to win a prize. There is a 1 in 5 chance that a bottle cap will have a prize. When your program runs your output should simply print a message indicating the average number of bottles of e-Boost you would need to drink to win a prize.
The steps are:
1. Determine how many bottle caps each person has to open in
order to find a winning cap. (This represents one trial.)
Print this value to a text file.
2. Prompt the user for the number of trials. Conduct at least 1000 trials.
3. Read back the data for all of the trials from the output file.
4. Calculate the average number of caps opened in order to win a prize.
5. Print the result to the screen."
Here's my code so far:
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.util.Scanner;
class BottleCapPrize
{
public static void main (String [ ] args) //throws IOException
{
int win = 0;
double randNum = 0.0;
int counter1 = 0;
int counter2 = 0;
int trials = 0;
Scanner in = new Scanner(System.in);
System.out.print("How many trials?: ");
trials = in.nextInt();
//PrintWriter outFile = new PrintWriter (new File("BottleCap.txt"));
randNum = Math.random();
randNum = randNum * 6;
while(counter1 <= trials)
{
while(randNum != 5)
{
counter2++;
System.out.println("Total bottles needed to find a winner:" + counter2);
}
counter1++;
}
System.out.println("Total bottle caps: " + counter2);
System.out.println("Total trials conducted: " + counter1);
//outFile.close();
}
}
I guess I don't have a specific question, but can someone please help me get some direction on this? I don't know how to continue in this assignment, and obviously something is wrong because it just prints infinite results.
This is also supposed to print into a text file, but I figured it would be easier to print the results onto the screen until I get a finished product.
Thank you!