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
|
import java.util.Random;
public class CardDeck {
private Card[] cards;
public CardDeck() {
cards = new Card[52];
String[] s = {"S","H","D","C"};
int a=0,b,c;
for (b=0;b<4;b++) {
for (c=0;c<13;c++) {
cards[a] = new Card(s[b],c+1);
a++;
}
}
}
public Card getCard(int i) {
return cards[i];
}
public CardDeck(boolean shuffle) {
cards = new Card[52];
String[] s = {"S","H","D","C"};
int a=0,b,c;
for (b=0;b<4;b++) {
for (c=0;c<13;c++) {
cards[a] = new Card(s[b],c+1);
a++;
}
}
if (shuffle) {
Random r = new Random();
Card temp;
int i,j;
for (i=0;i<cards.length;i++) {
j = r.nextInt(51);
temp = cards[i];
cards[i] = cards[j];
cards[j] = temp;
}
}
}
} |