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) { // initialize variables int numGamesPlayed = 0; double numPlayerwins = 0; double numDealerwins = 0; int numTies = 0; boolean play = true; int rand; Scanner scnr = new Scanner(System.in); P1Random random = new P1Random(); // start game while(play) { System.out.println("START GAME #" + (numGamesPlayed + 1)); int userHand = 0; // hand for user int dealerHand = 0; // hand for computer String card; rand = random.nextInt(13) + 1; // generate random number for card [1,13] switch(rand) { // turn random number into a string case 1: userHand += 1; card = "ACE"; break; case 11: userHand += 10; card = "JACK"; break; case 12: userHand += 10; card = "QUEEN"; break; case 13: userHand += 10; card = "KING"; break; default: userHand += (rand); card = Integer.toString(rand); break; } System.out.println("\nYour card is a " + card + "!"); System.out.println("Your hand is: " + userHand); boolean gameOver = false; while(!gameOver) { // Options menu, put in loop System.out.println("\n1. Get another card"); System.out.println("2. Hold hand"); System.out.println("3. Print statistics"); System.out.println("4. Exit"); System.out.print("\nChoose an option: ");

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture