Assignemnt #89 and Project #3 Code /// Name: Yordan Rashkov /// Period: 7 /// Program Name: Project 3 /// File Name: project3.java /// Date Finished: 3/14/2016 import java.util.Scanner; import java.util.Random; public class project3 { public static void main(String[] args) { Scanner kb = new Scanner(System.in); Random r = new Random(); int plh1 = 2 + r.nextInt(9); int plh2 = 2 + r.nextInt(9); int dl1 = 2 + r.nextInt(9); int dl2 = 2 + r.nextInt(9); String opt; int pHit; int dHit; int pt = plh1 + plh2; int dt = dl1 + dl2; System.out.println("LET'S PLAY SOME BLACKJACK!"); System.out.println(); System.out.println("You get a " + plh1 + " and a " + plh2 + "."); System.out.println("Your total is " + pt + "."); System.out.println(); if ( pt <= 21 ) { System.out.println("The dealer has a " + dl1 + " showing, and a hidden card."); System.out.println("His total is hidden, too."); System.out.println(); do { System.out.print("Would you like to \"hit\" or \"stay\"? "); opt = kb.next(); if (opt.equals("hit")) { pHit = 2 + r.nextInt(9); pt = pt + pHit; System.out.println("You drew a " + pHit + "."); System.out.println("Your total is " + pt + "."); System.out.println(); } } while (!opt.equals("stay") && pt <= 21); System.out.println("Okay, now its the dealer's turn."); System.out.println("His hidden card was a " + dl2 + "."); System.out.println("His total turned out to be " + dt + "."); System.out.println(); if (dt <= 21) { while (dt <= 16) { dHit = 2 + r.nextInt(9); dt = dt + dHit; System.out.println("Dealer chooses to hit."); System.out.println("He draws out a " + dHit + "."); System.out.println("His total is " + dt + "."); System.out.println(); } if (dt <= 21) { System.out.println("Dealer Stays."); System.out.println(); } } } System.out.println("Dealer total is " + dt + "."); System.out.println("Your total is " + pt + "."); System.out.println(); if (pt > dt && pt <= 21) System.out.println("Congratulations! You're a Winner!"); else if (pt < dt && dt <= 21) System.out.println("Well, this time the Dealer Wins!"); else if (pt == dt && pt <= 21) System.out.println("You have tied! The dealer is the winner!"); else if (pt > 21 && dt > 21) System.out.println("You Both Bust!"); else if (pt > 21) System.out.println("You Bust!"); else if (dt > 21) System.out.println("Dealer Busts!"); } }