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

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

import java.util.Scanner; public class Blackjack { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int playerWins = 0; int dealerWins = 0; int ties = 0; int gamesPlayed = 0; int gameNum = 0; boolean newGame = true; P1Random rng = new P1Random(); while (newGame == true){ boolean menu = true; gameNum += 1; int playerHand = 0; int dealerHand = 0; int cardsDrawn = 0; System.out.print("START GAME #" + gameNum); System.out.println(); System.out.println(); while (playerHand < 21){ cardsDrawn += 1; int cardValue = 0; int newCard = rng.nextInt(13) + 1; if (newCard < 10) { cardValue = newCard; } else { cardValue = 10; } playerHand += cardValue; if (newCard == 1){ String cardType = "ACE!"; System.out.print("Your card is a " + cardType); } else if (newCard == 11){ String cardType = "JACK!"; System.out.print("Your card is a " + cardType); } else if (newCard == 12){ String cardType = "QUEEN!"; System.out.print("Your card is a " + cardType); } else if (newCard == 13){ String cardType = "KING!"; System.out.print("Your card is a " + cardType); } else { String cardType = newCard +"!"; System.out.print("Your card is a " + cardType); }
System.out.println(); System.out.print("Your hand is: " + playerHand);

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture