It is essential that you make good use of functional abstraction in order to get full credit on this assignment. The 10 points of "Assignment specific correctness criteria" for this assignment will be based upon how well you have broken the problem into smaller subproblems with proper use of parameter passing.
You start with an initial bank roll of $100. The game is then played as follows.
I have provided a package "cards" that you must use to complete this assignment. The package cards has been placed in the same location as tio on the cats computers, so if you can use tio, then you should be able to use cards without any further action. To work with cards at home, you can install cards.jar just like you did tio.jar (be sure and right click the link in this sentence to save a copy of jar - left clicking won't work). Some of the classes in "cards" are similar to those in section 6.13 of the text. Everything you need related to the cards package for this assignment is shown in the following example. This example can also be found in /afs/cats/courses/cmps012a-cm/prog3/CardTest.java.
import cards.*;
class CardTest {
// args[0] is the seed for the random number generator.
// If there are no args, then a random seed is used.
public static void main(String[] args) {
// The deck is initialized with a random seed to randomize the cards.
// You only create the deck ONCE.
Deck deck;
if(args.length == 0)
deck = new Deck(); // just use a random seed for shuffling
else
deck = new Deck(Integer.parseInt(args[0])); // get seed from command line
// be sure and shuffle the deck each new hand
deck.shuffle();
Hand hand = new Hand();
// You add cards to the hand by drawing them from the deck.
hand.add(deck.draw());
System.out.println("The hand is " + hand);
hand.add(deck.draw());
System.out.println("The hand is " + hand);
// For the dealer hands you just show one card.
System.out.println("Showing only one card " + hand.showOne());
// You can determine the value of the hand treating Ace as one.
System.out.println("The hand total is " + hand.valueAce1());
// You can determine the value of the hand treating Ace as 11.
System.out.println("The hand total is " + hand.valueAce11());
}
}
java TwentyOne 123will run it with the seed 123 (you will get the same sequence of card if you run it again).
java TwentyOnewill give a different card sequence every time.
os-prompt>java TentyOne 9 Let's play twenty-one. You have $100. How much do you want to bet? Bet 0 to quit. 10 You have: 2:clubs 4:diamonds The dealer is showing: Ace:diamonds Do you want another card?[y/n] y Your hand is now: 2:clubs 4:diamonds Jack:diamonds Do you want another card?[y/n] n Dealer has: Ace:diamonds 8:diamonds Better luck next time. You have $90. How much do you want to bet? Bet 0 to quit. 10 You have: 6:spades 2:hearts The dealer is showing: 6:hearts Do you want another card?[y/n] y Your hand is now: 6:spades 2:hearts Ace:hearts Do you want another card?[y/n] n Dealer has: 6:hearts Ace:spades You win. You have $100. How much do you want to bet? Bet 0 to quit. 10 You have: Queen:hearts 8:spades The dealer is showing: 6:diamonds Do you want another card?[y/n] n Dealer has: 6:diamonds 7:spades Dealer takes another card. Dealer now has: 6:diamonds 7:spades Queen:diamonds You win. You have $110. How much do you want to bet? Bet 0 to quit. 10 You have: 10:clubs King:spades The dealer is showing: Queen:diamonds Do you want another card?[y/n] n Dealer has: Queen:diamonds King:hearts That's a push. You have $110. How much do you want to bet? Bet 0 to quit. 10 You have: 10:spades Jack:hearts The dealer is showing: Ace:diamonds Do you want another card?[y/n] n Dealer has: Ace:diamonds 9:hearts That's a push. You have $110. How much do you want to bet? Bet 0 to quit. 10 You have: King:clubs Jack:hearts The dealer is showing: 7:spades Do you want another card?[y/n] n Dealer has: 7:spades 10:clubs You win. You have $120. How much do you want to bet? Bet 0 to quit. 10 You have: 3:spades 4:clubs The dealer is showing: 4:spades Do you want another card?[y/n] y Your hand is now: 3:spades 4:clubs Jack:diamonds Do you want another card?[y/n] n Dealer has: 4:spades King:diamonds Dealer takes another card. Dealer now has: 4:spades King:diamonds 2:clubs Dealer takes another card. Dealer now has: 4:spades King:diamonds 2:clubs 3:clubs Better luck next time. You have $110. How much do you want to bet? Bet 0 to quit. 10 You have: 10:spades Ace:hearts The dealer is showing: King:diamonds Do you want another card?[y/n] n Dealer has: King:diamonds 10:hearts You win. You have $120. How much do you want to bet? Bet 0 to quit. 10 You have: 3:diamonds 2:hearts The dealer is showing: 10:clubs Do you want another card?[y/n] y Your hand is now: 3:diamonds 2:hearts Queen:spades Do you want another card?[y/n] y Your hand is now: 3:diamonds 2:hearts Queen:spades 7:clubs Dealer has: 10:clubs King:hearts Better luck next time. You have $110. How much do you want to bet? Bet 0 to quit. 0 os-prompt>Here is the sequence of input values used for the above run:
10 y n 10 y n 10 n 10 n 10 n 10 n 10 y n 10 n 10 y y 0The above intput sequence is also in /afs/cats/courses/cmps012a-cm/prog3/test1in.
If you run your program (or my sample solution) redirecting standard input to read from test1in and save the output in test2out, you should get the exact same output as I have placed in /afs/cats/courses/cmps012a-cm/prog3/test1out.
os-prompt:java TwentyOne < test1in > myoutput os-prompt:diff myoutput test1outThe above sequence should show no differences. Of course such file redirection is only for testing, wouldn't actually play the game that way.