outprintlnYour card is a QUEEN else iftemp 13 card is a

Outprintlnyour card is a queen else iftemp 13 card is

This preview shows page 1 - 3 out of 3 pages.

System.out.println("Your card is a QUEEN!"); else if(temp == 13) System.out.println("Your card is a KING!"); System.out.println("Your hand is: "+playerHand+"\n"); // print to screen when regular cards are dealt. // Print menu to screen for user's options. // Start a new game until user chooses option "4." from the menu. boolean theEnd = false; while(!theEnd) { System.out.print("1. Get another card\n2. Hold hand\n3. Print statistics \n 4. Exit \n\n Choose an option: "); choice = sc.nextInt(); switch(choice) { case 1:
Image of page 1
temp = rng.nextInt(13) + 1; playerHand = playerHand +((temp >= 10)? 10 : temp); if(temp == 1) System.out.println("Your card is a ACE!"); else if(temp <= 10) System.out.println("Your card is a "+temp+"!"); else if(temp == 11) System.out.println("Your card is a JACK!"); else if(temp == 12) System.out.println("Your card is a QUEEN!"); else if(temp == 13) System.out.println("Your card is a KING!"); System.out.println("Your hand is: "+playerHand+"\n"); // Print to screen what the user has been dealt. // Create if / else statements using user's options and cards dealt. if(playerHand == 21) // User wins with 21 points { System.out.println("BLACKJACK! You win!\n"); playerWins++; theEnd = true; } else if(playerHand > 21) // user loses if over 21 points are dealt and dealer wins. { System.out.println("You exceeded 21! You lose.\n"); dealerWins++; theEnd = true; } break; case 2: temp = rng.nextInt(11) + 16; System.out.println("Dealer's hand: "+temp); System.out.println("Your hand is: "+playerHand+"\n"); if(temp > 21) { System.out.println("You win!\n"); playerWins++; theEnd = true; } else if(temp == playerHand) { System.out.println("It's a tie! No one wins!\n");
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Spring '12
  • Staff
  • Playing card

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture