Semester 1 Final

Code

///Caelan Dorstad
///period 6
///Program Name: Sem1Final
///File Name: Sem1Final.java


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

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

             Scanner input = new Scanner(System.in);
            
	     System.out.println("Enter number of flips, please.");
	      	int flipnumb = input.nextInt ();
          
            while ( flipnumb < 1 || flipnumb > 2100000000 )
                
                System.out.print( "Your number was ");
	        	
            if ( flipnumb < 1 )
                {
		              System.out.println("Very small");
            }
            else
            {
                System.out.print("Very Large");
            }
            
            
            System.out.println("Please enter a number between 1 & 2.1B");
            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("During this trial, the probability of flipping heads was " + headProbability + ".");
          System.out.println("With the probability if tails being " + tailProbability + ".");
          
          
          
      }
}