Assignment P3 and Blackjack

Code

      /// Name: Jason Kim
      /// Period: 7
      /// Program Name: Blackjack
      /// File Name: Blackjack.java
      /// Date Finished:12/2/15
      
      import java.util.Random;
      import java.util.Scanner;
      
      public class Blackjack
      {
          public static void main(String[] args)
          {
              Random r = new Random();
              Scanner keyboard = new Scanner(System.in);
              
              System.out.println("Welcome to Jason's blackjack program!!\n");
              
              int playerCard1 = 2 + r.nextInt(10), playerCard2 = 2 + r.nextInt(10), playerTotal = playerCard1 + playerCard2;
              int dealerCard1 = 2 + r.nextInt(10), dealerCard2 = 2 + r.nextInt(10), dealerTotal = dealerCard1 + dealerCard2;
              int hit;
              String hitOrStay;
              
              System.out.println("You get a " + playerCard1 + " and " + playerCard2 + ".");
              System.out.println("Your total is " + playerTotal + ".\n");
              
              System.out.println("The dealer has " + dealerCard1 + " and a hidden card.");
              System.out.println("Dealer's total is hidden, too.");
              
              do
              {
                  System.out.println("\nWould you like to \"hit\" or \"stay?\"");
                  hitOrStay = keyboard.next();
                  if(hitOrStay.equals("hit"))
                  {
                      hit = 2 + r.nextInt(10);
                      playerTotal = playerTotal + hit;
                      System.out.println("\nYou drew a " + hit );
                      System.out.println("Your total is " + playerTotal);
                  }
              }while(hitOrStay.equals("hit") && playerTotal <= 21);
              
              if ( playerTotal > 21 )
              {
                  System.out.println("BUSTED!!! YOU LOSE!");
              }
              else
              {
                  System.out.println("\nOkay, dealer's turn.");
                  System.out.println("His hidden card was a " + dealerCard2 + ".");
                  System.out.println("His total was " + dealerTotal + ".");
      
                  while(dealerTotal <= 16 )
                  {
                      System.out.println("\nDealer chooses to hit.");
                      hit = 2 + r.nextInt(10);
                      System.out.println("He draws a " + hit + ".");
                      dealerTotal = dealerTotal + hit;
                      System.out.println("His total is " + dealerTotal + ".");
                  }
                  
                  if( dealerTotal > 21 )
                  {
                      System.out.println("Dealer is BUSTED! You win!");
                  }
                  else
                  {
                      System.out.println("\nDealer stays");
                      System.out.println("\nDealer total is " + dealerTotal + ".");
                      System.out.println("\nYour total is " + playerTotal + ".");
      
                      if ( playerTotal <= dealerTotal )
                      {
                          System.out.println("YOU LOSE!");
                      }
                      else
                      {
                          System.out.println("YOU WIN!");
                      }
                  }
              }
          }
      }
      

              

    

Picture of the output

AssignmentP3