Project #3 and Blackjack
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name:Blackjack
/// File Name: Blackjack2.java
/// Date Finished: 4/12/2016
import java.util.Scanner;
import java.util.Random;
public class Blackjack2
{
public static void main (String [] args)
{
Scanner stuff = new Scanner(System.in);
Random ran = new Random();
System.out.println("Welcome to Brian's blackjack table.");
String c="";
int card1 = 2+ ran.nextInt(10);
int card2 = 2+ ran.nextInt(10);
int d1 = 2+ ran.nextInt(10);
int d2 = 2+ ran.nextInt(10);
int total;
total=card1+card2;
int dtotal=d1+d2;
System.out.println("You got a "+card1+" and a "+card2+".");
System.out.println("Your total is "+total+".");
System.out.println();
System.out.println("The dealer is showing a "+d1+" and has a hidden card");
System.out.println("His total is hidden.");
System.out.println();
System.out.println("Would you like to 'hit' or 'stay'? ");
c=stuff.next();
while (c.equals("hit"))
{
int add = 2+ ran.nextInt(10);
System.out.println("You drew a "+add+".");
total=total+add;
System.out.println("Your new total is "+total+" now>");
System.out.println("Would you like to 'hit' or 'stay'? ");
c=stuff.next();
}
if (total==21)
System.out.println("Blackjack! You win!");
if (total>21)
{
System.out.println("You lose");
}
while (dtotal< 16)
{
System.out.println("Dealer choose to hit");
int add = 2+ran.nextInt(10);
System.out.println("Dealer drew a "+add+".");
dtotal = dtotal +add;
System.out.println("Dealer's total is "+dtotal+" now.");
}
if (dtotal>21)
{
System.out.println("The Dealer has a total of "+dtotal+".");
System.out.println("You win!!");
}
if (total>21)
System.out.println("You loss");
if (total< 21)
{
if (total>dtotal)
System.out.println("You win");
}
if (dtotal>total)
System.out.println("You lose");
}
}
Picture of the output