Assignemnt Final

Code

    /// Name: Brendan Miller
    /// Period: 5
    /// Program Name: Final
    /// File Name: Final.java
    /// Date Finished: 1/20/2016
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class Final
    {
    	public static void main( String[] args )
    	{
    		Scanner keyboard = new Scanner(System.in);
    		Random rng = new Random();
            
            int heads = 0;
            int tails = 0;
            int n = 0;  
            
            System.out.println("Welcome to the First Semester Final!");
            System.out.println("How many coin flips would you like?");
            int flips = keyboard.nextInt();
            do
            {
                int flip = rng.nextInt(2);
                
                if ( flip == 1 )
                    heads++;
                else
                    tails++;
            n++;
            }
            while (n != flips);
            System.out.println("---------------------------------------------");
            System.out.println("Heads: " + heads + " ");
            System.out.println("Tails: " + tails + " ");
            System.out.println("---------------------------------------------"); 
            
            double probOfHeads = (double)heads / flips;
            double probOfTails = (double)tails / flips; 
            
            System.out.println("Probability of heads: " + probOfHeads*100 + "%");
            System.out.println("Probability of tails: " + probOfTails*100 + "%");
            //I choose to use a do while because it stops at the correct number given. Plus I like do whiles more.
        }
    }
    

Picture of the output

Assignment 1