Objective:
Write a Java program that will allow a user to play one hand of the card game Blackjack, or
Twenty-One, as its sometimes known. The rules, for the purpose of this assignment, are as
follows:
Blackjack rules:
The game is played with a deck of standard paying cards.
A player is dealt 2 cards to start the “hand”
A player’s score is the sum of the value of all cards in their hand, where:
o Cards numbered 2 through 10 are worth their numerical value
o Picture cards (Jack, Queen, King) are worth 10 points
o Aces are worth either 1 or 11 points
The player then has the choice to “hit” or “stand”
o If the player “stands”, their turn is finished
o If the player “hits”, they are dealt another card and the score is updated
Play continues until the player “stands”, gets 21, or “busts” (see below)
o The current score is then final
The object is to get 21, or as close as possible, without going over
If the final score is over 21, the player “busts”, i.e. loses
o Initially, an ace is valued at 11, but…
o if an 11 would lead to a “bust”, it is re-valued at 1
If the player gets 21 with the first 2 cards (i.e. an Ace and a card worth 10), they have
“Blackjack”
Normally, Blackjack is played competitively, where hands are dealt to both players and the
dealer in a casino. Bets are placed and the players attempt to outscore the dealer, thereby
winning their bet. In this assignment, we will only deal one player’s hand (no dealer, no bets).
Assignment Description:
For this assignment, we will associate each card in a standard playing deck with an integer “id”
code having a value ranging from 0 to 51. Each card will also be represented with a 2 character
string of the form “RS” where R is the rank and “S” is the suit. The rank and the suit can be
determined using the following arrays and formulas:
String[] ranks = {“A”, “2”, “3”, “4” ,”5″, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”};
String[] suits = {“S”, “H”, “C”, “D”};
R= id % 13; // the one character string containing the card rank
S= id / 13 // the one character string containing the card suit
Thus for an id == 31, the 2 character card string is “6C”, representing the six of clubs
Create a Java class called Assignment1. Include a main() method in which one hand of
Blackjack will be played. The program should, in main(), deal the first two cards and display
Assembly Language Question

0 comments