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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* Simulation of console-I/O program Blackjack, using ConsoleApplet as a basis. See the file for more information. David Eck */ * 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; } }...
View Full Document

This note was uploaded on 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

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 Right Arrow Icon
Ask a homework question - tutors are online