forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPile.java
More file actions
47 lines (39 loc) · 874 Bytes
/
Pile.java
File metadata and controls
47 lines (39 loc) · 874 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
43
44
45
46
47
import java.util.ArrayList;
/**
* A pile of playing cards (of variable size).
*/
public class Pile {
private ArrayList<Card> cards;
/**
* Constructs an empty pile of cards.
*/
public Pile() {
this.cards = new ArrayList<Card>();
}
/**
* Adds a card to the bottom of the pile.
*/
public void addCard(Card card) {
this.cards.add(card);
}
/**
* Copies an entire deck into the pile.
*/
public void addDeck(Deck deck) {
for (Card card : deck.getCards()) {
this.cards.add(card);
}
}
/**
* Returns true if this pile has no cards.
*/
public boolean isEmpty() {
return this.cards.isEmpty();
}
/**
* Removes a card from the top of the pile.
*/
public Card popCard() {
return this.cards.remove(0);
}
}