{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

BlackjackConsole

# BlackjackConsole - Simulation of console-I/O program...

This preview shows pages 1–2. Sign up to view the full content.

/* Simulation of console-I/O program Blackjack, using ConsoleApplet as a basis. See the file ConsoleApplet.java for more information. David Eck [email protected] */ * public class BlackjackConsole extends ConsoleApplet { p protected String getTitle() { return "Blackjack!"; } protected void program() { /* This program lets the user play Blackjack. The computer acts as the dealer. The user has a stake of \$100, and makes a bet on each game. The user can leave at any time, or will be kicked out when he loses all the money. House rules: The dealer hits on a total of 16 or less and stands on a total of 17 or more. Dealer wins ties. A new deck of cards is used for each game. */ int money; // Amount of money the user has. int bet; // Amount user bets on a game. boolean userWins; // Did the user win the game? console.putln("Welcome to the game of blackjack."); console.putln(); money = 100; // User starts with \$100. while (true) { console.putln("You have " + money + " dollars."); do { console.putln("How many dollars do you want to bet? (Enter 0 to end.)"); console.put("? "); bet = console.getlnInt(); if (bet < 0 || bet > money) console.putln("Your answer must be between 0 and " + money + '.'); } while (bet < 0 || bet > money); if (bet == 0) break; userWins = playBlackjack(); if (userWins) money = money + bet; else money = money - bet; console.putln(); if (money == 0) { console.putln("Looks like you've are out of money!"); break; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

BlackjackConsole - Simulation of console-I/O program...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online