Skip to content
Snippets Groups Projects
Commit a488433d authored by Scott Langum Du Plessis's avatar Scott Langum Du Plessis
Browse files

Merge branch 'add-deckOfCards-class' into 'main'

Added DeckOfCards class

See merge request !2
parents 55236386 87e1dcd6
No related branches found
No related tags found
1 merge request!2Added DeckOfCards class
package edu.ntnu.stud.cardgame;
import java.util.ArrayList;
import java.util.Random;
import java.util.List;
public class DeckOfCards {
private final char[] suit = { 'S', 'H', 'D', 'C' };
private final List<PlayingCard> deck;
Random random = new Random();
public DeckOfCards(){
deck = new ArrayList<>();
for (int i = 0; i < 52; i++) {
int face = random.nextInt(13)+1;
int suitNum = random.nextInt(4);
deck.add(new PlayingCard(suit[suitNum], face));
}
}
public List<PlayingCard> getDeck() {
return deck;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (PlayingCard card : deck) {
sb.append(card.getAsString());
sb.append("\n");
}
return sb.toString();
}
}
......@@ -22,5 +22,7 @@ public class Main extends Application {
public static void main(String[] args) {
launch(args);
DeckOfCards deck = new DeckOfCards();
System.out.println(deck);
}
}
......@@ -87,4 +87,6 @@ public class PlayingCard {
hash = 31 * hash + getFace();
return hash;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment