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