-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.java
More file actions
56 lines (48 loc) · 1.08 KB
/
Copy pathHand.java
File metadata and controls
56 lines (48 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package blackJack;
import java.util.ArrayList;
import java.util.List;
/**
* A class to represent the hand of cards of either a dealer or player
* @author Adam Wiener
*
*/
public class Hand {
private List<Card> _cards;
public Hand () {
_cards = new ArrayList<Card>();
}
public void addCardToHand(Card card) {
_cards.add(card);
}
public int handValue() {
int score = 0;
for (Card card: _cards) {
int cardVal = card.getCardValue();
if (cardVal == 1 && score < 11) {
cardVal = 11;
}
score += cardVal;
}
return score;
}
public Card getCardFromHand(int pos){
if (pos > _cards.size() || _cards.size() == 0) {
return null;
}
return _cards.get(pos);
}
public String displayHand() {
if (_cards.size() == 0) {
return "";
}
String string = "";
for (int i = 0; i<_cards.size(); i++) {
string = string + _cards.get(i).displayCard() + " ";
}
return string;
}
public String displayHandWithScore() {
String string = displayHand() + "Score: "+ handValue();
return string;
}
}