Final

Code

          /// Name: Holden Ganch
          /// Period: 7
          /// Program Name:  Fall Final
          /// File Name: Final.java
          /// Date Finished: 1/21/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 r = new Random();
            int NF = 0;
            int NH = 0;
            int NT = 0;
            int flip = 0;
                
            System.out.println("How many times would you like for the coined to be flipped? ");
            System.out.print("> ");
            NF = keyboard.nextInt();
            
            if ( NF <= 0 )
            {
                System.out.println("Your number must be a whole number greater than zero");
                System.out.println("I ask you again, how many times do you want the coined flipped? ");
                System.out.print("> ");
                NF = keyboard.nextInt();
            }
            
            if (NF > 2100000000)
            {
                System.out.println("Wow, really that many times -_-, it has to be less that 2.1 billion buddy. ");
                System.out.println("For real though, how many times do you want the coined to be flipped? ");
                System.out.print("> ");
                NF = keyboard.nextInt();
            }
            
            do
            {
                int x = 1 + r.nextInt(2);
                
                if ( x == 1)
                    NH ++;
                else
                    NT ++;
                flip++;
            }
            while ( flip != NF );
            
            System.out.println("\n\n\n Heads = " + NH);
            System.out.println("\n Tails = " + NT);
            
            double PH = (double)NH/NT;
            double PT = (double)NT/NH;
            double PHH = PH/2;
            double PTT = PT/2;
                
            System.out.println("\n\n\nProbability of Head = " + PHH);
            System.out.println("\nProbability of Tail = " + PTT);
            } 
            
        // If statements work really well for specific variables and for setting the "rules" to follow. 
        // when using  do and while loops they are good for keeping track of big numbers keeping up with them if they change
        //the bigger the number the closser to .50 you get because it evens out when finding the probability. Thus making           2,100,000,000 is the best number to use to get as close to a 50-50 chance of head and tails and because it is the         highest number that a computer can use.
    }

 

            
        



    

Picture of the output

Assignment final