outprintlnUser has the userHandgetCard0 and the userHandgetCard1

Outprintlnuser has the userhandgetcard0 and the

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

System.out.println("User has the " + userHand.getCard(0) + " and the " + userHand.getCard(1) + "."); System.out.println(); System.out.println("You have Blackjack. You win."); return true; } //If the players don't have Black Jack right off the game resumes you can H or S. while (true) { //Display user's cards - lets the user decide to either H or S System.out.println(); System.out.println(); System.out.println("Your cards are:"); for ( int i = 0; i < userHand.getCardCount(); i++ ) System.out.println(" " + userHand.getCard(i)); System.out.println("Your total is " + userHand.getBlackjackValue()); System.out.println(); System.out.println("Dealer is showing the " + dealerHand.getCard(0));System.out.println();System.out.println("Hit (H) or Stand (S)? ");char userAction; // User input to hit or stand: 'H' or 'S'.do {Scanner s = new Scanner(System.in);userAction = s.next().charAt(0);if (userAction != 'H' && userAction != 'S')System.out.println("Please respond H or S: ");} while (userAction != 'H' && userAction != 'S');/* * If the user enter H, the user gets a card. * If the user enters S, the loop ends and it's the dealer's turn to draw cards.*/if ( userAction == 'S' ) {// Loop ends; user is done taking cards.break;}else { //'H' = ive the user a card. // If the user goes over 21 with new card drawn, the user loses the game.Card newCard = deck.dealCard();userHand.addCard(newCard);System.out.println();System.out.println("User hits.");System.out.println("Your card is the " + newCard);System.out.println("Your total is now " +
Image of page 3
System.out.println(); System.out.println("You busted by going over 21. You lose."); System.out.println("Dealer's other card was the " + dealerHand.getCard(1)); return false; } } } // end while loop //If the game makes it to this point the user has Stood with 21 or less. //Dealer's chance to draw. Dealer draws cards until the total > 16 System.out.println(); System.out.println("User stands."); System.out.println("Dealer's cards are"); System.out.println(" " + dealerHand.getCard(0)); System.out.println("
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Spring '10
  • LEHMAN

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture