Assignemnt #92
Code
/// Name: Connor Siri
/// Period: 7
/// Program Name: Blackjack
/// File Name: Blackjack.java
/// Date Finished: 12/4/2015
import java.util.Random;
import java.util.Scanner;
public class Blackjack
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int C1 = 2 + r.nextInt(10), C2 = 2 + r.nextInt(10), D1 = 2 + r.nextInt(10), D2 = 2 + r.nextInt(10) ;
int Ptotal = C1 + C2;
int Dtotal = D1 + D2;
String HoS;
HoS = "" ;
System.out.println("Blackjack!");
System.out.println("\n You drew a " + C1 + " and " + C2);
System.out.println("Your total is " + Ptotal );
System.out.println("\nThe Dealer has " + D1 + " and a hidden card");
System.out.println("Dealer's total is hidden");
System.out.print("\nWould you like to \"hit\" or \"stay\" ");
HoS = keyboard.next();
while (HoS.equals("hit"))
{
if (HoS.equals("hit"))
{
int CH = 2 + r.nextInt(10);
Ptotal = Ptotal + CH;
System.out.println("You got a " + CH);
System.out.println("Your Total is " + Ptotal);
System.out.print("Would you like to \"hit\" or \"stay\" ");
HoS = keyboard.next();
}
}
System.out.println("\nThe Dealer flips his card and it is a " + D2);
System.out.println("His total is " + Dtotal);
while ( Dtotal < 16 )
{
int DC = 2 +r.nextInt(10);
Dtotal = Dtotal + DC;
System.out.println("\nThe Dealer hit and now his total is " + Dtotal);
}
if ( Ptotal < 21 && Dtotal < 21 )
{
if ( Ptotal > Dtotal )
{
System.out.println("\nYou win");
}
else if ( Dtotal > Ptotal )
{
System.out.println("\nThe dealer wins.");
}
}
if ( Ptotal > 21 && Dtotal > 21 )
{
System.out.println("\nYou both bust");
}
else if (Ptotal > 21 )
{
System.out.println("The dealer wins");
}
else if ( Dtotal > 21 )
{
System.out.println("\nYou win");
}
else if ( Dtotal == Ptotal )
{
System.out.println("\nIt is a tie, split the pot");
}
}
}
Picture of the output