Project: Blackjack

///Name: Ilana Levy
///Period: 5
///Program Name: Blackjack
///File Name: blackjack.java
///Date Finished: 10/11/2015

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

public class blackjack
{
        public static void main( String[] args )
        {
                Scanner keyboard = new Scanner( System.in );
                Random r = new Random();
            
                String play;
                int x = 2 + r.nextInt(9), y = 2 + r.nextInt(9), dealer1 = 2 + r.nextInt(9), yourTotal = x + y, dealer2 = 2 + r.nextInt(9), dealerTotal = dealer1 + dealer2;
                
                
                System.out.println( "Welcome to Ilana's blackjack program!");
                System.out.println( "You get a " + x + " and a " + y + "\nYour total is " + yourTotal );
                System.out.println();
                
                System.out.println( "The dealer has a " + dealer1 + " showing, \nHis total is hidden, too." );
                System.out.println();
                
                System.out.println( "Would you like to \"hit\" or \"stay\"?" );
                        play = keyboard.next();
            
                while( !play.equals("stay") || yourTotal <= 21 )
                {
                        int z = 2 + r.nextInt(9);
                        yourTotal = yourTotal + z;
                    
                        System.out.println( "You drew a " + z + ".\nYour total is " + yourTotal );
                        
                        if( yourTotal > 21 )
                        {
                            System.out.println( "You went over 21. DEALER WINS!" );
                            play = "stay";
                        }
                        else if (yourTotal <= 21 )
                        {
                            System.out.println( "Would you like to \"hit\" or \"stay\"?" );
                            play = keyboard.next();
                            System.out.println();
                        }
                }                         

                if (yourTotal <= 21) 
                {
                        System.out.println( "Okay, dealer's turn.\n his hidden card was a " + dealer2 + ".\nHis total was " + dealerTotal + "." );
                    
                    while (dealerTotal < 16 )
                    {
                            int dealerHit = 2 + r.nextInt(9);
                            dealerTotal = dealerTotal + dealerHit;
                            System.out.println( "Dealer chooses to hit.\n He draws a " + dealerHit + ".\nHis total is " + dealerTotal );
                    }
                    
                    System.out.println( "Dealer stays." );
                    
                    System.out.println( "Dealer total is " + dealerTotal + ".\nYour total is " + yourTotal + ".");
                    
                    if (dealerTotal > yourTotal && dealerTotal < 22)
                    System.out.println( "DEALER WINS");
                    else
                    System.out.println( "YOU WIN!");
                }
                
                
        }
}