Semester 1 Final

Code

    /// Name: Mahima Choudhary
    /// Period: 6
    /// Program Name: Final
    /// File Name: Final.java
    /// Date Finished: 1/21/2016
    
    import java.util.Scanner;
    import java.util.Random;
    
    public class Final {
    
    public static void main(String[] args) {
    
        Scanner keyboard = new Scanner(System.in);
        Random r = new Random();
        
        int flips = 1, heads = 0, tails = 0;
        
        System.out.println();
        System.out.println( "HIIIIII this is Mahima Choudhary's coin-flip game and I challenge you!" );
        
        do {
            System.out.print( "How many times will you be flipping the coin? " );
            flips = keyboard.nextInt ();
            } while ( flips <=0 || flips > 2100000000 );
            
            for ( int i = 1; i <= flips; i++ ) {
                int side = 1;
                side = r.nextInt (2);
                
                if ( side == 0 ) {
                    heads++;
                    } else {
                        tails++;
                    }
                }
                
                double probHeads = 100 * heads/flips;
                double probTails = 100 * tails/flips;
                
         System.out.println( "Great Job!! You got + " + heads + " number of heads and " + tails + " number of tails." );
         System.out.println( " The probability of flipping heads was " + probHeads + "%" );
         System.out.println( " The probability of flipping tails was " + probTails + "%" );
         
         }
    }
    
    /// In conclusion percentages of either heads or tails HAS to be larger than the other
    /// It will be 49% to 50%
    /// Design choices: statements cause it is able to check each time to see whether to add the one to which side of the coin
    /// I used a for loop because it seemed easier to do to inorder to repeat it the amount of times chosen
    /// Awesome, thanks for your time
    
 

Picture of the output

Assignment 1