{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

BlackjackHand

# BlackjackHand - int cardVal The blackjack value of the i-th...

This preview shows page 1. Sign up to view the full content.

C /* A subclass of the Hand class that represents a hand of cards in the game of Blackjack. To the methods inherited form Hand, it adds the method getBlackjackHand(), which returns the value of the hand for the game of Blackjack. */ * public class BlackjackHand extends Hand { public int getBlackjackValue() { // Returns the value of this hand for the // game of Blackjack. int val; // The value computed for the hand. boolean ace; // This will be set to true if the // hand contains an ace. int cards; // Number of cards in the hand. val = 0; ace = false; cards = getCardCount(); for ( int i = 0; i < cards; i++ ) { // Add the value of the i-th card in the hand. Card card; // The i-th card;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int cardVal; // The blackjack value of the i-th card. card = get±ard(i); cardVal = card.getValue(); // The normal value, 1 to 13. if (cardVal > 10) { cardVal = 10; // For a Jack, Queen, or King. } if (cardVal == 1) { ace = true; // There is at least one ace. } val = val + cardVal; } // Now, val is the value of the hand, counting any ace as 1. // If there is an ace, and if changing its value from 1 to // 11 would leave the score less than or equal to 21, // then do so by adding the extra 10 points to val. if ( ace == true && val + 10 <= 21 ) val = val + 10; return val; } // end getBlackjackValue() } // end class BlackjackHand }...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern