Semester 1 Final Project

Code

    /// Name: Boris Kazantsev
    /// Period: 6
    /// Program Name: FinalS1
    /// File Name: FinalS1.java
    /// Date Finished: 1/22/2016
    
    import java.util.Scanner;
    import java.util.Random;


public class FinalS1
{
    public static void main( String[] args ) {

        Scanner input = new Scanner(System.in);

            System.out.println("Hello welcome to coin toss");

                System.out.println("PLease select amount of coin tosses");
                int flipNum = input.nextInt();
            {
                 System.out.println(" uh oh, your number was ");
                    if ( flipNum < 1 )
                    {
                                    System.out.print("too small");
                                    
                    }
                    else
                    {
                                    System.out.print("too large");
                    }
                    System.out.println("Please select a number between 1 and 2,100,000,000.");
            }
                                    
            Random r = new Random();
                        
            int flipsCompleted = 0;
            int headTotal = 0;
            int outcome = 0;
                                    
                    while ( flipsCompleted < flipNum );
                        {
                    outcome =r.nextInt(2);
                    headTotal= headTotal + outcome;
                    flipsCompleted++;
                        }

        int tailTotal = flipsCompleted - headTotal;
        
        System.out.println("In " + flipNum + " coin flips, " + headTotal + " heads were rolled and" + tailTotal + "tails were rolled.");
        double headProbability = (double)headTotal / flipsCompleted;
        double tailProbability = (double)tailTotal / flipsCompleted;
                                    
    System.out.println("In this trial, the probability of rolling a head was " + headProbability +".");
    System.out.println("The probability of rolling a tails was " + tailProbability + ".");
        }
}

   
    

Picture of the output

sem1