Skip to content
Snippets Groups Projects
Commit 55314c3e authored by Ole-Thomas Sundvoll Moe's avatar Ole-Thomas Sundvoll Moe
Browse files

Added javadoc

parent 820698e3
Branches main
No related tags found
No related merge requests found
{ java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(ÁÉ¿ùûÿÿÿÿ8´ëòÌå1
\ No newline at end of file
W
java:S1128":Remove this unused import 'javafx.scene.layout.StackPane'.(81
\ No newline at end of file
......@@ -3,16 +3,25 @@ package org.OleThomas;
import java.util.ArrayList;
import java.util.Random;
/**
* Represents a deck of playing cards.
*
* @see PlayingCard
* @author Ole-Thomas
* @version 1.0
*/
public class DeckOfCards {
private ArrayList<PlayingCard> deckOfCards;
private char[] suits = {'S', 'H', 'D', 'C'};
/** Creates an instance of a deck of cards with all cards accounted for. */
public DeckOfCards() {
deckOfCards = new ArrayList<PlayingCard>();
shuffleDeck();
}
/** "Shuffels" a deck of playing cards to get all used cards back. */
public void shuffleDeck() {
deckOfCards.clear();
PlayingCard tmp = null;
......@@ -24,15 +33,21 @@ public class DeckOfCards {
}
}
/**
* Getter for deckOfCards
*
* @return deckOfCards
*/
public ArrayList<PlayingCard> getDeckOfCards() {
return deckOfCards;
}
/**
* Getter for deckOfCards size
*
* @return deckOfCards.size()
*/
public int getSize() {
return deckOfCards.size();
}
public static void main(String[] args) {
System.out.println(new PlayingCard('S', 12).hashCode());
}
}
package org.OleThomas;
import com.sun.javafx.binding.StringFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
* Represents an instance of a hand of cards.
*
* @see PlayingCard
* @author Ole-Thomas
* @version 1.0
*/
public class Hand {
private ArrayList<PlayingCard> hand;
private Random random = new Random();
private char[] suits = {'S', 'H', 'D', 'C'};
/**
* Creates an instance of a hand of cards.
*
* @param n number of cards in the hand
* @param deckOfCards the deck of cards to draw from
*/
public Hand(int n, DeckOfCards deckOfCards) {
this.hand = dealHand(n, deckOfCards);
}
/**
* "Draws" a hand of cards
*
* @param n number of cards in the hand
* @param deckOfCards the deck of cards to draw from
* @return hand
*/
public ArrayList<PlayingCard> dealHand(int n, DeckOfCards deckOfCards) {
if (n < 1 || n > deckOfCards.getSize()) {
throw new IllegalArgumentException("Invalid number of cards to deal");
......@@ -34,11 +52,21 @@ public class Hand {
return hand;
}
/**
* Method to find the sum of the faces in the hand.
*
* @return sum
*/
public int sumOfTheFaces() {
int sum = hand.stream().mapToInt(card -> card.getFace()).sum();
return sum;
}
/**
* Method to find the cards with hearts as the face.
*
* @return String of cards or "No Hearts" for no hearts
*/
public String getHearts() {
List<String> hearts =
hand.stream()
......@@ -57,16 +85,38 @@ public class Hand {
}
}
/**
* Method to find if a hand contains the queen of spades.
*
* @return boolean
*/
public boolean containsQueenOfSpade() {
boolean queenOfSpades =
hand.stream().anyMatch(card -> card.getSuit() == 'S' && card.getFace() == 12);
return queenOfSpades;
}
/**
* Method to find if a hand contains a five flush.
*
* @return boolean
*/
public boolean containsFiveFlush() {
return false;
boolean fiveFlush = false;
for (char suit : suits) {
long sum = hand.stream().filter(card -> card.getSuit() == suit).count();
if (sum == 5) {
fiveFlush = true;
}
}
return fiveFlush;
}
/**
* toString method
*
* @return string
*/
@Override
public String toString() {
StringBuilder txt = new StringBuilder();
......
......@@ -4,12 +4,14 @@ import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
* Main application of the program
*/
public class Main extends Application {
Stage window;
......
......@@ -3,8 +3,17 @@ package org.OleThomas;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test class for PlayingCard class.
*
* @see PlayingCard
* @author Ole-Thomas
* @version 1.0
*/
class PlayingCardTest {
/** Positive test for playingCard */
@Test
void posPlayingCard() {
PlayingCard card1 = new PlayingCard('S', 12);
......@@ -13,6 +22,7 @@ class PlayingCardTest {
assertEquals(card1.getFace(), 12);
}
/** Negative test for playingCard */
@Test
void negPlayingCard() {
PlayingCard card1 = new PlayingCard('S', 12);
......@@ -21,18 +31,21 @@ class PlayingCardTest {
assertNotEquals(card1.getFace(), 15);
}
/** Positive test for getAsString */
@Test
void posGetAsString() {
PlayingCard card1 = new PlayingCard('S', 12);
assertEquals(card1.getAsString(), "S12");
}
/** Negative test for getAsString */
@Test
void negGetAsString() {
PlayingCard card1 = new PlayingCard('S', 12);
assertNotEquals(card1.getAsString(), "H13");
}
/** Positive test for equals */
@Test
void posTestEquals() {
PlayingCard card1 = new PlayingCard('S', 12);
......@@ -41,8 +54,7 @@ class PlayingCardTest {
assertTrue(card2.equals(card1));
}
/** Negative test for equals */
@Test
void negTestEquals() {
PlayingCard card1 = new PlayingCard('S', 12);
......@@ -50,6 +62,8 @@ class PlayingCardTest {
assertFalse(card1.equals(card2));
assertFalse(card2.equals(card1));
}
/** Positive test for hashCode. */
@Test
void testHashCode() {
PlayingCard card1 = new PlayingCard('S', 12);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment