for int suit 0 suit 3 suit for int value 1 value 13 value deckcardCt value

For int suit 0 suit 3 suit for int value 1 value 13

This preview shows page 2 - 4 out of 7 pages.

Image of page 2
/* Check if one of the players has Blackjack (two cards totaling to 21). The player with Blackjack wins the game. Dealer wins ties. */ if (value(dealerHand) == 21) { System.out.println("Dealer has the " + showCard(getCard(dealerHand, 0)) + " and the " + showCard(getCard(dealerHand, 1)) + "."); System.out.println("User has the " + showCard(getCard(userHand, 0)) + " and the " + showCard(getCard(userHand, 1)) + "."); System.out.println(); System.out.println("Dealer has Blackjack. Dealer wins."); return false; } if (value(userHand) == 21) { System.out.println("Dealer has the " + showCard(getCard(dealerHand, 0)) + " and the " + showCard(getCard(dealerHand, 1)) + "."); System.out.println("User has the " + showCard(getCard(userHand, 0)) + " and the " + showCard(getCard(userHand, 1)) + "."); System.out.println(); System.out.println("You have Blackjack. You win."); return true; } /* If neither player has Blackjack, play the game. The user gets a chance to draw cards (i.e., to "Hit"). The while loop ends when the user chooses to "Stand" or when the user goes over 21. */ while (true) { /* Display user's cards, and let user decide to Hit or Stand. */ System.out.println(); System.out.println(); System.out.println("Your cards are:"); for (int i = 0; i < userHand.size(); i++) { System.out.println(" " + showCard(getCard(userHand, i))); } System.out.println("Your total is " + value(userHand)); System.out.println(); System.out.println("Dealer is showing the " + showCard(getCard(dealerHand, 0))); System.out.println(); System.out.print("Hit (H) or Stand (S)? "); char userAction; // User's response, 'H' or 'S'.
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture