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

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

import java.util.Scanner; public class Blackjack { public static void main(String[] args) { //instantiate all variables to be used in the blackjack game, game, wins, losses, ties. int game = 0; int wins = 0; int losses = 0; int ties = 0; //instantiate variables used for inner and outer loops boolean gameover; boolean exit = false; //instantiate P1Random object to be used to generate cards P1Random rng = new P1Random(); //create scanner to be used for the menu feature. Scanner choice = new Scanner(System.in); //start outer loop that will contain entire game, will allow game to run until user chooses 'exit' option do{ //print out START GAME message //increment game integer to allow counting of games game=game+1; System.out.print("\n\nSTART GAME #" + game); //reset gameover boolean to false to allow inner loop to run gameover=false; //instantiate 'hand' variable which is used to show the total sum of the player's cards at any given time int hand=0; //instantiate 'firstcard' variable which is the card that is automatically given to the player at the beginning of each game int firstcard = rng.nextInt(13)+1; // if, else-if statements to account for the card being given to them being a king, queen, jack or ace // which have a value of 10, but are generated as 11,12,13 or 1 // needed because the word printed to the user is not the number generated, but the name of the card. if (firstcard<=10 && firstcard>1) { System.out.print("\n\nYour card is a " + firstcard + "!"); hand = hand+firstcard; } else if (firstcard==1) { System.out.print("\n\nYour card is a ACE!"); hand = hand+firstcard; } else if (firstcard==11) { System.out.print("\n\nYour card is a JACK!"); hand = hand+firstcard-3; } else if (firstcard==12) { System.out.print("\n\nYour card is a QUEEN!");

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture