From 9346c4222389381a0b320b7d03f6b4b7e7cfc44a Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 16:11:22 +0100 Subject: [PATCH] implement CardDeck with 52 Cards --- src/main/java/solitaer/Card.java | 28 ++++++++++++++++++++++++ src/main/java/solitaer/CardDeck.java | 23 +++++++++++++++++++ src/test/java/solitaer/CardDeckTest.java | 21 ++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/main/java/solitaer/Card.java create mode 100644 src/main/java/solitaer/CardDeck.java create mode 100644 src/test/java/solitaer/CardDeckTest.java diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java new file mode 100644 index 0000000..38bb04d --- /dev/null +++ b/src/main/java/solitaer/Card.java @@ -0,0 +1,28 @@ +package solitaer; + +import javax.swing.JPanel; + +enum Symbol { + Herz, Karo, Kreuz, Pik +} + +public class Card extends JPanel { + + /** + * + */ + private static final long serialVersionUID = 1L; + private int nr; + private Symbol symbol; + + private boolean faceUp; + + public Card(int nr, Symbol symbol, boolean faceUp) { + this.nr = nr; + this.symbol = symbol; + this.faceUp = faceUp; + } + + + +} diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java new file mode 100644 index 0000000..522a7fd --- /dev/null +++ b/src/main/java/solitaer/CardDeck.java @@ -0,0 +1,23 @@ +package solitaer; + +import java.util.ArrayList; + +public class CardDeck { + + private ArrayList deck = new ArrayList(); + + + public CardDeck() { + for(int i= 0; i<52; i++) { + deck.add(new Card(i, Symbol.Herz, false)); + } + + } + + + public ArrayList getDeck() { + return deck; + } + + +} diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java new file mode 100644 index 0000000..751c85d --- /dev/null +++ b/src/test/java/solitaer/CardDeckTest.java @@ -0,0 +1,21 @@ +package solitaer; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class CardDeckTest { + + @Test + void testCardDeckSize() { + CardDeck deck = new CardDeck(); + + int result = deck.getDeck().size(); + + assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ; + + } + + + +}