Assignment #70 Flip Again

Code

    
    /// Name: Lacey Reese 
    /// Period: 5
    /// Program Name:  FlipAgain
    /// File Name:  FlipAgain.java
    /// Date Finished 1/8/2016
    
  

      import java.util.Random;

    import java.util.Scanner;
    
    public class FlipAgain
    {
    
        //3. The program still works when "again" isn't set equal to "y" because the do while loops executes the content before checking it 
    }

    	public static void main( String[] args )
    	{
    		Scanner keyboard = new Scanner(System.in);
    		Random rng = new Random();
    
    		String again;
    
    		do
            {
    			int flip = rng.nextInt(2);
    			String coin;
    
    			if ( flip == 1 )
    				coin = "HEADS";
    			else
    				coin = "TAILS";
    
    			System.out.println( "You flip a coin and it is... " + coin );
    
    			System.out.print( "Would you like to flip again (y/n)? " );
    			again = keyboard.next();
    		} while ( again.equals("y") );
    	}
    }
    
    /// 3. Because "again" is designated a value before the condition is evaluated, the program still works.

    

    

Picture of the output

// Assignment 70