-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
41 lines (34 loc) · 1.02 KB
/
Deck.java
File metadata and controls
41 lines (34 loc) · 1.02 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
package com.pslin.cards;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a standard deck of 52 playing cards.
*
* @author plin
*/
public class Deck {
private List<Card> cards = new ArrayList<>();
public Deck() {
buildDeck();
}
private void buildDeck() {
for(int i=Card.MIN_VALUE; i <= Card.MAX_VALUE; i++) {
cards.add(new Card(i, Card.Suit.CLUB));
cards.add(new Card(i, Card.Suit.DIAMOND));
cards.add(new Card(i, Card.Suit.HEART));
cards.add(new Card(i, Card.Suit.SPADE));
}
}
public List<Card> getCards() {
return cards;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder("Deck{ ");
for(Card card : cards) {
stringBuilder.append(card.getDisplayValue()).append(card.getSuit().getUnicode()).append(" ");
}
stringBuilder.append('}');
return stringBuilder.toString();
}
}