Results of this round based on value of hand if

This preview shows page 4 - 6 out of 6 pages.

//results of this round based on value of handif(playerHand > 21){System.out.println("You exceeded 21! You lose.");numGamesPlayed ++;numDealerWins ++;gameNum++;playerHand = 0;//situation which the user loses and dealer wins}if(playerHand == 21){System.out.println("BLACKJACK! You win!");numGamesPlayed ++;numPlayerWins++;gameNum++;playerHand = 0;//situation which player wins after the dealing of cards}}if(selection == 2){dealerHand = rng.nextInt(11) + 16;System.out.println("Dealer's hand: " + dealerHand);System.out.println("Your hand is: " + playerHand);if(dealerHand > 21){System.out.println("You win!");numGamesPlayed ++;numPlayerWins++;gameNum++;playerHand = 0;}else if(playerHand > dealerHand && playerHand < 21){System.out.println("You win!");numGamesPlayed ++;
numPlayerWins++;gameNum++;playerHand = 0;}else if(dealerHand < playerHand && playerHand < 21){System.out.println("Dealer wins!");numDealerWins ++;numGamesPlayed ++;gameNum++;playerHand = 0;}else if(playerHand == dealerHand && playerHand < 21){System.out.println("It's a tie! No one wins!");numTies ++;numGamesPlayed ++;gameNum++;playerHand = 0;}}if(selection == 3){if(numGamesPlayed > 1) {double percentPlayerWins = (numPlayerWins / numGamesPlayed) * 100;System.out.println("Number of Player Wins: " + numPlayerWins);System.out.println("Number of Dealer wins: " + numDealerWins);System.out.println("Number of tie games: " + numTies);System.out.println("Total # of games played is: " + numGamesPlayed);System.out.println("Percentage of player wins: " + percentPlayerWins + "%");}else{System.out.println("Number of Player Wins: " + numPlayerWins);System.out.println("Number of Dealer wins: " + numDealerWins);System.out.println("Number of tie games: " + numTies);System.out.println("Total # of games played is: 0");System.out.println("Percentage of player wins: 0%" );}}if(selection == 4){run = false;
}else if(selection < 1 || selection > 4){System.out.println("Invalid input!");System.out.println("Please enter an integer value between 1 and 4.");}}}}

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture