Class Card

  • All Implemented Interfaces:
    java.lang.Comparable<Card>

    public class Card
    extends java.lang.Object
    implements java.lang.Comparable<Card>
    Objects of this class representing a card known from a standard card game.
    Since:
    16.08.2016 18:13:23
    Author:
    Nico Danneberg
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Suit suit
      The suit of this card.
      private Value value
      The value of this card.
    • Constructor Summary

      Constructors 
      Constructor Description
      Card​(java.lang.String vs)
      Creates a card with value and suit read from the given string.
    • Method Summary

      Modifier and Type Method Description
      int compareTo​(Card c)
      Compares two cards using their numeric value of the value.
      boolean equals​(java.lang.Object o)
      Checks of two cards are equal to each other.
      int getNumericValue()
      Just a getter of the value's numeric value.
      Suit getSuit()
      Just a getter of the suit.
      Value getValue()
      Just a getter of the value.
      boolean hasSameSuit​(Card c)
      Tests if a given card has the same suit like this card.
      boolean hasSameValue​(Card c)
      Tests if a given card has the same value like this card.
      boolean set​(java.lang.String vs)
      Sets the value and suit of the current card by the given string of two characters.
      java.lang.String toString()
      Creates a string representation as combination of value and suit of this card.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • suit

        private Suit suit
        The suit of this card.
      • value

        private Value value
        The value of this card.
    • Constructor Detail

      • Card

        public Card​(java.lang.String vs)
             throws java.lang.IllegalArgumentException
        Creates a card with value and suit read from the given string. This string is a two-character code for all possible card combinations, e.g. "TH" for a Ten of Hearts.
        Parameters:
        vs - a two-character string storing the value and suit of the card
        Throws:
        java.lang.IllegalArgumentException - if the given string can not be interpreted as cards suit and value
    • Method Detail

      • compareTo

        public int compareTo​(Card c)
        Compares two cards using their numeric value of the value. If these are equal the suits are compared.
        Specified by:
        compareTo in interface java.lang.Comparable<Card>
        Parameters:
        c - the other card
        Returns:
        1 of this card is higher, -1 if it is lower, and 0 if both cards are equal
      • equals

        public boolean equals​(java.lang.Object o)
        Checks of two cards are equal to each other.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - a second card
        Returns:
        true if compareTo(Card) returns 0
      • getNumericValue

        public int getNumericValue()
        Just a getter of the value's numeric value.
        Returns:
        the value's numeric value
        See Also:
        Value.getValue()
      • getSuit

        public Suit getSuit()
        Just a getter of the suit.
        Returns:
        the suit
      • getValue

        public Value getValue()
        Just a getter of the value.
        Returns:
        the value
      • hasSameSuit

        public boolean hasSameSuit​(Card c)
        Tests if a given card has the same suit like this card.
        Parameters:
        c - another card
        Returns:
        true, if both cards have the same suit
      • hasSameValue

        public boolean hasSameValue​(Card c)
        Tests if a given card has the same value like this card.
        Parameters:
        c - another card
        Returns:
        true, if both cards have the same value
      • set

        public boolean set​(java.lang.String vs)
        Sets the value and suit of the current card by the given string of two characters. E.g. the string "TH" is interpreted as a ten of hearts.
        Parameters:
        vs - a two character string combined of value and suit
        Returns:
        true if both, value and suit, can be read from given string
      • toString

        public java.lang.String toString()
        Creates a string representation as combination of value and suit of this card.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a two character string of this card