-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDeck.java
More file actions
41 lines (32 loc) · 861 Bytes
/
Deck.java
File metadata and controls
41 lines (32 loc) · 861 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
package blackjack.domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Deck {
private final List<Card> cards;
public Deck() {
cards = new ArrayList<>();
setupCard();
shuffle();
}
private void setupCard() {
for (Suit suit : Suit.values()) {
setDenomination(suit);
}
}
private void setDenomination(Suit suit) {
for (Denomination denomination : Denomination.values()) {
cards.add(new Card(suit, denomination));
}
}
private void shuffle() {
Collections.shuffle(cards);
}
public Card popCard() {
Card popped = cards.remove(0);
return new Card(popped.getSuit(), popped.getDenomination());
}
public int getCardsCount() {
return cards.size();
}
}