Project #3

Code

///John Mulligan
///period 5
///Program Name: BlackJack
///File Name: BlackJack.java

     import java.util.Random;
        import java.util.Scanner;
        
        public class BlackJack
        {
            public static void main(String[] args)
            {
                Scanner kb = new Scanner(System.in);
                Random r = new Random();
                
                int u1, u2, d1, d2, c,  utotal, dtotal;
                u1 = 2 + r.nextInt(10);
                u2 = 2 + r.nextInt(10);
                d1 = 2 + r.nextInt(10);
                d2 = 2 + r.nextInt(10);   
                utotal = u1 + u2;
                dtotal = d1 + d2;
                
                System.out.println("THIS IS MAJOR LEAGE BLACK JACK!");
                System.out.println("You drew a " + u1 + " and a " + u2 + ".");
                System.out.println("Your total is " + utotal + ".");
                System.out.println("");
                System.out.println("The dealer has a " + d1 + " showing, and 1 unknown card.");
                System.out.println("Opponents total is hidden..");
                System.out.println("");
                
                System.out.print("Would you like to 'hit!' or 'stay'? ");
                String choice = kb.next();
                while (choice.equals("hit!") && utotal <= 21)
                {
                    c = 2 + r.nextInt(10);
                    utotal = utotal + c;
                    
                    System.out.println("You drew a " + c + ".");
                    System.out.println("Your total is " + utotal + ".");
                    System.out.println("");
                    
                    if (utotal <= 21)
                    {
                        System.out.print("Would you like to 'hit!' or 'stay'? ");
                        choice = kb.next();
                    }
                    
                    else
                    {
                        System.out.println("Its ogre now. Win to the dealer!");
                    }
                }
                
                if (utotal <= 21)
                {
                    System.out.println("");
                    System.out.println("Dealer your turn!");
                    System.out.println("Dealer's unkown card is a " + d2 + ".");
                    System.out.println("And his total is " + dtotal + ".");
                }
                
                while (utotal <= 21 && dtotal <= 16)
                {
                    c = 2 + r.nextInt(10);
                    dtotal = dtotal + c;
                    System.out.println("");
                    System.out.println("The Dealer is going to hit.");
                    System.out.println("Drawing a " + c + ".");
                    System.out.println("Dealers total is " + dtotal + ".");
                    System.out.println("");
                }
                
                if (dtotal > 21)
                {
                    System.out.println("YOUR THE VICTOR!");
                }
                
                else if (dtotal <= 21 && utotal <= 21)
                {
                    if (utotal > dtotal)
                        System.out.println("YOU WIN! Heres you check of $5");
                    
                    else if (utotal < dtotal)
                        System.out.println("The dealer wins!");
                    else
                        System.out.println("Stand down its a draw.");
                }            
            }
        }