Blackjack.java - import java.util.Scanner public class...

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

import java.util.Scanner; public class Blackjack { public static void main(String[] args) { P1Random randGen = new P1Random(); Scanner scnr = new Scanner(System.in); int playersHand = 0; int dealersHand = 0; int randomPlayersCard; int gameNumber = 1; int playersOption = 1; int playerWins = 0; int dealerWins = 0; double percentageWins; int tieGames = 0; int totalGames = 0; boolean endGame = false; while (playersOption != 4) { if (playersHand >= 21 || playersHand == 0 || dealersHand >= 21 || endGame == true) { // establish conditions for a new game System.out.println("START GAME #" + gameNumber + "\n"); // Start a new game gameNumber = gameNumber + 1; playersHand = 0; // set initial player's hand to 0 dealersHand = 0; // set initial dealer's hand to 0 endGame = false; randomPlayersCard = randGen.nextInt(13) + 1; //Draw random player's card if (randomPlayersCard == 1) { // Assign different names to cards System.out.println("Your card is a ACE!"); } else if (randomPlayersCard >= 2 && randomPlayersCard <= 10) { System.out.println("Your card is a" + " " + randomPlayersCard + "!"); } else if (randomPlayersCard == 11) { System.out.println("Your card is a JACK!");

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture