Project 3, BlackJack
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Project 3
///File Name: BlackJack.java
///Date Finshed: 5/31/16
import java.util.Scanner;
import java.util.Random;
public class BlackJack
{
public static void main ( String[] args )
{
Scanner siri = new Scanner(System.in);
Random r = new Random();
String choice2= " ";
int a = 1 + r.nextInt(10);
int b = 1 + r.nextInt(10);
int suma = (a + b);
int x = 1 + r.nextInt(10);
int y = 1 + r.nextInt(10);
int sumb = (y + x);
System.out.println("You drew "+ a +" and "+ b+".");
System.out.println("Your total is "+ suma+".");
System.out.println(" ");
System.out.println("The dealer drew "+a+" and hidden card.");
System.out.println("The dealer's total is hidden as well.");
System.out.println("Would you like to hit or stay ?");
System.out.print(" > ");
String choice = siri.next();
if (choice.equals("hit"));
{
do
{
int c = 1 + r.nextInt(10);
suma = suma + c;
if (suma <= 21)
{
System.out.println("Your total is " +suma+ ". Would you like to hit or stay?");
System.out.print(" > ");
choice2 = siri.next();
}
}while (choice2.equals("hit"));
if (suma > 21)
{
System.out.println("You bust dealer wins");
System.out.println(" ");
}
}
if (choice2.equals("stay"))
{
System.out.println("The dealer's hidden card was "+b);
System.out.println("Their total is " +sumb);
while (sumb <=16 )
{
int z = 1 + r.nextInt(10);
sumb = sumb + z;
System.out.println("The dealer's new total is "+sumb);
}
if (sumb > 21 && suma < 22)
System.out.println("Player Wins!");
if (suma > sumb )
System.out.println("Player Win!");
if (suma < sumb || suma == sumb)
System.out.println("Dealer Wins!");
if (suma >21 && sumb >21)
System.out.println("No one Wins!");
}}}
Picture of the output