Skip to content
Snippets Groups Projects

Resolve "Oppgave 2"

Merged Nathalie Graidy Andreassen requested to merge 2-oppgave-2 into main
1 file
+ 37
0
Compare changes
  • Side-by-side
  • Inline
package no.ntnu.idatt2003.demo;
import java.util.ArrayList;
import java.util.Collections;
/**
* Represents a Deck of cards, in an arraylist containing playing cards.
*/
public class DeckOfCards {
private final ArrayList<PlayingCard> deckOfCards;
/**
* Instantiates a new Deck of cards.
*/
public DeckOfCards() {
deckOfCards = new ArrayList<PlayingCard>();
}
/**
* Fills deck array list, with playing card objects. The method uses a two-dimensional loop to
* through every possible combinations of playing cards and adds them to the deck of cards.
* The method uses Collections shuffle to make sure the order of the playing cards are random.
*
* @return deckOfCards (array list)
*/
public ArrayList<PlayingCard> FillDeck() {
char[] suits = { 'S', 'H', 'D', 'C' };
for (char suit : suits) {
for (int value = 1; value <= 13; value++) {
deckOfCards.add(new PlayingCard(suit, value));
}
}
Collections.shuffle(deckOfCards);
return deckOfCards;
}
}
Loading