-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathParticipantCards.java
More file actions
42 lines (31 loc) · 960 Bytes
/
ParticipantCards.java
File metadata and controls
42 lines (31 loc) · 960 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;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ParticipantCards {
private static final String COMMA = ", ";
private final List<Card> cards;
public ParticipantCards(List<Card> cards) {
this.cards = new ArrayList<>(cards);
}
public void addCards(List<Card> drawCards) {
cards.addAll(drawCards);
}
public int sumCardScore() {
return cards.stream()
.reduce(0, (x, y) -> x + y.getScore(x), Integer::sum);
}
public List<Card> getCards() {
return Collections.unmodifiableList(cards);
}
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cards.size(); i++) {
sb.append(cards.get(i).toString());
if (i != cards.size() - 1) {
sb.append(COMMA);
}
}
return sb.toString();
}
}