what i am supposed to do is calculate the chances of wining a bottle top prize if there is one in five winners. i have to do it a difficult way though. i made a random number that signifies a win when it lands on one. i then have to output how many wins vs. loses to a file. next i have to import it back and use it to calculate how many drinks you would need to buy in order to win once, and print this to the screen. my problem is that once i bring the file back in i dont know how to use it to make the calculations. i have this much already so thats pretty much all i have left to do.
/**
*
*
* Nathan Gibson
*
*/
import java.util.Scanner;
import java.util.Random;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
public class BottleCapPrize
{
public static void main(String [] args)throws IOException
{
Scanner in;
in = new Scanner(System.in);
int randomNumber = ((int)(0+ Math.random()* 5));
int counter = 0;
int winCounter = 0;
PrintWriter outFile = new PrintWriter (new File("bottleCap.txt"));
while(counter < 20)
{
randomNumber = ((int)(0+ Math.random()* 5));
outFile.println("Wins: " + winCounter + " Total: " + counter);
if (randomNumber == 1)
{
winCounter++;
counter++;
}
else
{
counter++;
}
}
outFile.close ( );
String token = "";
File fileName = new File("bottleCap.txt");
Scanner inFile = new Scanner(fileName);
while (inFile.hasNext())
{
UNKNOWN
}
inFile.close();
}
}