-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
35 lines (31 loc) · 718 Bytes
/
Deck.java
File metadata and controls
35 lines (31 loc) · 718 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
import java.util.ArrayList;
import java.util.Random;
public class Deck {
private ArrayList<Card> cards = new ArrayList<Card>();
public Deck() {
for (int i = 1; i <= 13; i++) {
add(new Card(Card.CLUBS, i));
add(new Card(Card.DIAMONDS, i));
add(new Card(Card.HEARTS, i));
add(new Card(Card.SPADES, i));
}
}
public void add(Card c) {
cards.add(c);
}
public void print() {
System.out.println("Printing Cards: ");
for (Card c : cards) {
System.out.println(c.getRealNumber() + " of " + c.getSuit());
}
}
public int getSize(){
return cards.size();
}
public Card getRandom() {
int i = (int) (Math.random() * getSize());
Card c = cards.get(i);
cards.remove(i);
return c;
}
}