Assignement: Project 3: Playing Blackjack
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: BlackJack
/// File Name: BlackJack.java
/// Date Finished: 3/11/2016
import java.util.Scanner;
import java.util.Random;
public class BlackJack
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
String response;
int PlayerValue1, PlayerValue2, NewPlayerValue, HitPlayerValue, DealerValue1, DealerValue2, DealerValue3, PlayerTotal, DealerTotal;
System.out.println( "Welcome to play some BlackJack man " );
DealerValue3 = 0;
HitPlayerValue = 0;
NewPlayerValue = 0;
PlayerValue1 = 1 + r.nextInt(10);
PlayerValue2 = 1 + r.nextInt(10);
DealerValue1 = 1 + r.nextInt(10);
DealerValue2 = 1 + r.nextInt(10);
PlayerTotal = PlayerValue1 + PlayerValue2;
DealerTotal = DealerValue1 + DealerValue2;
System.out.println ( "You drew a " + PlayerValue1 + " and " + PlayerValue2 + " . ");
System.out.println( " Your total is " + PlayerTotal + "." );
System.out.println();
System.out.println( " The dealer has a " + DealerValue1 + " and the other card is hidden. " );
System.out.println( " The Dealer's total is hidden." );
System.out.println( "Would you like to \"hit\" or \"stay\" ");
response = keyboard.next();
if ( response.equals("hit"))
{
NewPlayerValue = 1 + r.nextInt(10);
PlayerTotal = PlayerTotal + NewPlayerValue;
System.out.println( " You drew a " + NewPlayerValue + " . ");
System.out.println( " Your total is " + PlayerTotal + " . ");
}
while ( response.equals( "hit" ) )
{
System.out.println( "Would you like to \"hit\" or \"stay\" ");
response = keyboard.next();
if ( response.equals("hit"))
{
HitPlayerValue = 1 + r.nextInt(10);
PlayerTotal = PlayerTotal + HitPlayerValue;
System.out.println( " You drew a " + NewPlayerValue + " . ");
System.out.println( " Your total is " + PlayerTotal + " . ");
}
}
if ( DealerTotal < 16 )
{
DealerValue3 = 1 + r.nextInt(10);
DealerTotal = DealerTotal + DealerValue3;
System.out.println( "Dealer chooses to hit ");
System.out.println( "He draws a " + DealerValue3 + " ." );
System.out.println( "His total is " + DealerTotal + " .");
}
if ( PlayerTotal >= DealerTotal || DealerTotal >= 21 )
{
System.out.println( " You win! " );
}
else if ( PlayerTotal >= 21 )
{
System.out.println( " You Loose! " );
}
else
{
System.out.println( " You Loose! " );
}
}
}
Picture of the output