Skip to content

Commit 968a3f2

Browse files
committed
added Cards\src\Main\Deck.java
1 parent 343037e commit 968a3f2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Cards/src/Main/Deck.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Main;
2+
3+
public class Deck {
4+
5+
static String[] SUIT = {"H","C","S","D"};
6+
static String[] RANK = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
7+
static String[] DECK = new String[SUIT.length*RANK.length];
8+
9+
public static void main(String[] args){
10+
MakeDeck();
11+
ShowDeck();
12+
}
13+
14+
15+
public static void MakeDeck(){
16+
for(int X = 0; X<DECK.length; X++){
17+
DECK[X] = RANK[X%RANK.length] + SUIT[X/RANK.length];
18+
19+
}
20+
}
21+
public void ShuffleDeck(){
22+
for (int X=0; X<DECK.length; X++) {
23+
int RAND = (int)(Math.random() * DECK.length); // returns a double so it has to be casted to int
24+
25+
String TEMP = DECK[X];
26+
DECK[X] = DECK[RAND]; // the index at element X becomes element with index of the corresponding X element on the INDARR
27+
DECK[RAND] = TEMP;
28+
}
29+
30+
System.out.println("--------Deck shuffled");
31+
32+
}
33+
34+
35+
36+
public static void ShowDeck(){
37+
for (String c : DECK){
38+
System.out.println(c);
39+
}
40+
}
41+
42+
}

0 commit comments

Comments
 (0)