-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardBundle.java
More file actions
42 lines (31 loc) · 913 Bytes
/
CardBundle.java
File metadata and controls
42 lines (31 loc) · 913 Bytes
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
package blackjack.domain.card;
import blackjack.domain.score.ScoreCalculator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CardBundle {
private static final int BLACK_JACK_SCORE = 21;
private final List<Card> cards;
private CardBundle() {
this.cards = new ArrayList<>();
}
public static CardBundle emptyBundle() {
return new CardBundle();
}
public void addCard(Card card) {
cards.add(card);
}
public int calculateScore() {
return ScoreCalculator.findByCards(cards)
.calculateScore(cards);
}
public List<Card> getCards() {
return Collections.unmodifiableList(cards);
}
public boolean isBurst() {
return calculateScore() > BLACK_JACK_SCORE;
}
public boolean isBlackJack() {
return calculateScore() == BLACK_JACK_SCORE;
}
}