Skip to content
Snippets Groups Projects
Commit b027704b authored by Torbjørn Antonsen's avatar Torbjørn Antonsen
Browse files

Implemented HandOfCards class and methods for gettingn sum of faces and size of hand

parent 988571d9
No related branches found
No related tags found
1 merge request!5Implemented HandOfCards class and methods for gettingn sum of faces and size of hand
......@@ -17,7 +17,7 @@ public class DeckOfCards {
}
}
public PlayingCard[] dealHand(int n) {
public HandOfCards dealHand(int n) {
List<PlayingCard> drawDeck = deckOfCards;
PlayingCard[] hand = new PlayingCard[n];
Random random = new Random();
......@@ -29,7 +29,8 @@ public class DeckOfCards {
hand[j] = drawDeck.get(i);
drawDeck.remove(i);
}
return hand;
return new HandOfCards(hand);
}
public List<PlayingCard> getDeckOfCards() {
......
package edu.ntnu.idatt2001;
import java.util.List;
public class HandOfCards {
private final PlayingCard[] hand;
public HandOfCards(PlayingCard[] hand) {
this.hand = hand;
}
public int getSize() {
return hand.length;
}
public int getSumOfFaces() {
int sum = 0;
for (PlayingCard playingCard : hand) {
sum += playingCard.getFace();
}
return sum;
}
}
......@@ -21,7 +21,7 @@ class DeckOfCardsTest {
@Test
public void dealHandDealsRightAmountOfCards() {
DeckOfCards doc = new DeckOfCards();
assertEquals(5, doc.dealHand(5).length);
assertEquals(5, doc.dealHand(5).getSize());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment