Assignemnt FINAL And Display Probability
Code
///Name: Daniel Rhees
///Period: 5
///Project Name: Dispay Probability
///File Name: DisplayProbability.java
///Date: 1/20/2016
import java.util.Random;
import java.util.Scanner;
public class DisplayProbability
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "How many times do you want to flip the coin ?" );
int flipnumb = input.nextInt ();
while ( flipnumb < 1 || flipnumb > 2100000000 )
{
System.out.print( "Your number was: " );
if ( flipnumb < 1 )
{
System.out.println( "Your number is too small." );
}
else
{
System.out.print( "Your number is too big." );
}
}
System.out.println( "Please enter a number between 1 - 2,100,000,000" );
flipnumb = input.nextInt();
Random r = new Random();
int flipsflipped = 0;
int heads = 0;
int outcome = 0;
while ( flipsflipped < flipnumb )
{
outcome = r.nextInt(2);
heads = heads + outcome;
flipsflipped++;
}
int tailTotal = flipsflipped - heads;
System.out.println( "In " + flipnumb + " coin flips, " + heads + " heads were rolled and " + tailTotal + " tails were rolled." );
double headProbablility = (double) heads / flipsflipped;
double tailProbablility = (double) tails / flipsflipped;
System.out.println( "The probability of rolling heads in this run was " + headProbability + "." );
System.out.println( "With a probability if tails being " + tailProbability + "." );
}
}