Assignment Final

Code

 ///Name: Conner Wygaerts
///Period: 6
///Project Name: Final1
///File Name: Final1.java
///Date Finished: 1/22/16

import java.util.Random;
import java.util.Scanner;

public class Final1
{
    public static void main( String[] args )
    {
        Scanner keyboard = new Scanner(System.in);
        Random rng = new Random();
        
        int Another = 0;
        int flips, Heads, Tails;
        
        Heads = 0;
        Tails = 0;
        //numbers start at 0
        System.out.print("How many times would you like to flip the coin?" ); //question
        flips = keyboard.nextInt();
        
        while ( flips < 1 || flips > 2100000000 )
        {
            System.out.println ("Sorry that number is ");
            
            if ( flips < 1 )
            {
                System.out.println ("too small");
            }
            else if ( flips > 2100000000 )
            {
                System.out.println ("too large");
            }
            
            System.out.println("Please pick a number between 1 and 2,100,000,000. ");
            flips = keyboard.nextInt();
        }
        
            do
            {
                int flip = rng.nextInt(2);
                String coin;
                
                if ( flip == 1 )
                {
                    coin = "Heads";
                    Another++;
                    Heads++;
                }
                else
                {
                    coin = "Tails";
                    Another++;
                    Tails++;
                }
                System.out.println ("The coin flips and is " + coin );
            } while (Another < (flips) );
        //while loop repeats coin flips
        double probabilityofheads = (double)Heads / flips;
        double probabilityoftails = (double)Tails / flips;
        
        double percentheads = (probabilityofheads * 100);
        double percenttails = (probabilityoftails * 100);
        
                System.out.println ("There were " + Heads + " Heads flipped and " + Tails + " Tails flipped."); //make percentage of probability
                System.out.println ("The probability of getting Heads was " + percentheads + "%");//tells percent of head
                System.out.println ("The probability of getting Tails was " + percenttails + "%");//tells percent of tail
    
    //numbers that end in 0 or are multiple of 10 are more likely to be come out 50%
    }
}  
                
    
  

Picture of the output

YourInitials.html