-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeck.java
More file actions
41 lines (33 loc) · 945 Bytes
/
Deck.java
File metadata and controls
41 lines (33 loc) · 945 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
import java.util.*;
public class Deck {
private List<Card> cards = new ArrayList<Card>();
private String[] suits = {"spades", "hearts", "diamonds", "spades"};
private String[] names = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"};
public Deck() {
for (int i = 0; i < 13; i++) {
for (int j = 0; j < 4; j++) {
cards.add(new Card(names[i], i, suits[j]));
}
}
}
public Deck(List<Card> cards) {
this.cards = cards;
}
public void shuffle() {
Collections.shuffle(cards);
}
public Card deal() {
Card temp = cards.get(0);
cards.remove(0);
return temp;
}
public int length() {
return cards.size();
}
public List<Card> getCards() {
return cards;
}
public void addCard(Card card) {
cards.add(card);
}
}