import java.util.Scanner; /** * BlackJack class. * * @author John Paxton * @version October 15, 2008 */ public class BlackJack { public static void main (String [] args) { CardDeck deck = new CardDeck(); int lowerBound; int upperBound = 21; Scanner in = new Scanner (System.in); System.out.println("CS 160, Program 3, BlackJack Simulator"); System.out.println("--------------------------------------\n"); System.out.println("The upper bound is 21."); System.out.println("Please enter the lower bound"); lowerBound = getInteger(1, 21, in); deck.initializeSimulation(lowerBound, upperBound); for (int i = 0; i < SIMULATIONS; i++) { deck.simulateBlackJack(); } System.out.println("\nResults for [" + lowerBound + ", " + upperBound + "]\n"); System.out.println("Number of wins = " + deck.getWins()); System.out.println("Number of losses = " + deck.getLosses()); System.out.println("Total games = " + SIMULATIONS); } private static int getInteger (int lower, int upper, Scanner in) { int answer = lower - 1; while ((answer < lower) || (answer > upper)) { System.out.print("Enter an integer between " + lower + " and " + upper + ": "); if (in.hasNextInt()) { answer = in.nextInt(); } in.nextLine(); } return answer; } public static final int SIMULATIONS = 1000000; }