Fall Final

Code

      ///Name: Ian Grant
      ///Period:5
      ///Project Name: Final
      ///File Name:Final.java
      ///01/20/16
      
      import java.util.Random;
      import java.util.Scanner;
      public class Final
      {
          public static void main(String[] args)
          {
              int flip=0;
              int i=1;
              int numHeads=0;
              int numTails=0;
              Scanner stuff = new Scanner(System.in);
              Random r = new Random();
              System.out.println("How many times do you want the coin to flip?");
              flip=stuff.nextInt();
              if (flip< 1 || flip >2100000001)
              {
                System.out.println("Error number between 1 and 2.1 billion");
                System.out.println("How many times do you want the coin to flip?");
                flip=stuff.nextInt();
              }
              do
              {
                  int ran = 1+r.nextInt(2);
                  if (ran == 1)
                      {
                          //I wanted to display each coin flip for fun
                          System.out.println("Heads");
                          numHeads++;
                      }
                  else if (ran == 2)
                      {
                          //I wanted to display each coin flip for fun
                          System.out.println("Tails");
                          numTails++;
                      }
                  i++;
              } while (flip>=i);
              double probOfHeads = (double)numHeads / flip;
              double probOfTails = (double)numTails / flip;
              System.out.println("You flip "+numHeads+" number of heads and "+numTails+" number of Tails.");
              System.out.println("Probility of fliping heads is "+probOfHeads+".");
              System.out.println("Probility of fliping tails is "+probOfTails+".");
              
            /*
            2.1 Billion is the consistent that gets the probability as close as possible to 50%
            */
          }
      }
      

Output