Ok, so basically I am supposed to "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."
I know that I am supposed to First, work on the part that conducts trials and print the results to the screen. Second, print the results of each trial to an outFile. Check the file to verify it matches the screen output. Third, read the trial data back in and calculate the average. Fourth, print the results.
Ok so here is what I have so far
import java.util.Scanner;
import java.util.Random;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
public class BottleCap
{
public static void main(String [] args)throws IOException
{
int trials = 20;
int count = 0;
Scanner in;
in = new Scanner(System.in);
int randomnumber = ((int)(0+ Math.random()* 999));
PrintWriter outFile = new PrintWriter(new File("bcp.txt"));
for(int loop = 1; loop <= 20;)
{
int randomNumber = ((int)(0+ Math.random()* 999));
outFile.println(randomnumber);
}
outFile.close ();
Scanner inFile = new Scanner(outFile);
System.out.print(inFile);
inFile.close();
}
}
Im not really sure I am doing it right or even headed in the right direction... Any ideas?