Assignemnt Project #3
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Program Name: Project3 Program
/// File Name: Project3.java
/// Date Finished: 9/9/2015
import java.util.Scanner;
import java.util.Random;
public class Project3
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int x = 1 + r.nextInt(10);
int y = 1 + r.nextInt(10);
int a = 1 + r.nextInt(10);
int b = 1 + r.nextInt(10);
int ab = 1 + r.nextInt(10);
int ac = 1 + r.nextInt(10);
int aa = 1 + r.nextInt(10);
int z = x + y;
int c = a + b;
String decision = "";
System.out.println("You drew " + x + " and " + y + ".");
System.out.println("Your total is " + z + ".");
System.out.println("");
System.out.println("The dealer has a " + a + " and a hidden card.");
System.out.println("The dealer's total is hidden.");
System.out.println("");
System.out.println("Would you like to 'hit' or 'stay'?");
int turn = 0;
while (turn != 1) {
decision = keyboard.next();
if (decision.equals("hit")) {
System.out.println("You draw a " + aa + ".");
z = aa + z;
System.out.println("Your total is now " + z + ".");
}
else if (decision.equals("stay")) {
System.out.println("Okay dealer's turn");
System.out.println("His hidden card was a " + ab + ".");
System.out.println("His total was " + c + ".");
turn = 1;
}
}
if (c < 15) {
System.out.println("Dealer chooses to hit.");
System.out.println("He draws a " + ac + ".");
System.out.println("His total is " + c + ".");
}
System.out.println("Dealer stays.");
System.out.println("His total is " + c + ".");
System.out.println("Your total is " + z + ".");
if (z > 21)
System.out.println("You lose");
if (c > 21)
System.out.println("You win!");
if (c > z)
System.out.println("You lose!");
if (z > c)
System.out.println("You win!");
else if (z == c)
System.out.println("Its a tie..");
}
}
Picture of the output