Untitled (2).txt - import java.text.DecimalFormat import...

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

import java.text.DecimalFormat;import java.util.Scanner;public class Blackjack {public static void main(String[] args) {P1Random rng = new P1Random();boolean play = true;int round = 1;int wins = 0;int losses = 0;int ties = 0;int playerTotal = 0;int dealerTotal = 0;int card = rng.nextInt(13);String[] cards = new String[]{"ACE", "2", "3", "4", "5", "6", "7", "8", "9", "10", "JACK", "QUEEN", "KING"};Scanner scanner = new Scanner(System.in);do {System.out.println("START GAME #" + round + "\n");System.out.println("Your card is a " + cards[card] + "!");playerTotal += (card > 9) ? 10 : card+1;System.out.println("Your hand is: " + playerTotal + "\n");play = true;do {System.out.println("1. Get another card\n2. Hold hand\n3. Print statistics\n4. Exit\n\nChoose an option: ");String input = scanner.next();if (input.charAt(0) > '0' && input.charAt(0) < '5') {int num = input.charAt(0) - '0';switch (num) {case 1:card = rng.nextInt(13);System.out.println("Your card is a " + cards[card] +"!");playerTotal += (card > 9) ? 10 : card+1;System.out.println("Your hand is: " + playerTotal + "\n");if (playerTotal > 21) play = false; break;case 2:dealerTotal = rng.nextInt(11) + 16;

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture