Package javatro.core
Record Class Card
java.lang.Object
java.lang.Record
javatro.core.Card
Represents a playing card with a rank and a suit in a card game. Each card has a specific rank
(e.g., ACE, KING) and suit (e.g., HEARTS, SPADES). The card's rank determines both its display
symbol and its chip value in gameplay.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.intgetChips()Returns the chip value of this card based on its rank.final inthashCode()Returns a hash code value for this object.rank()Returns the value of therankrecord component.suit()Returns the value of thesuitrecord component.toString()Returns a human-readable string representation of the card.
-
Constructor Details
-
Card
Compact constructor to validate card components. -
Card
Constructs a new card by copying an existing card instance.- Parameters:
other- The card to copy. Must not benull.
-
-
Method Details
-
getChips
public int getChips()Returns the chip value of this card based on its rank.- Returns:
- Chip value for game calculations
-
toString
Returns a human-readable string representation of the card. Format: "[Symbol] of [Suit]" (e.g., "A of Hearts"). -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
rank
Returns the value of therankrecord component.- Returns:
- the value of the
rankrecord component
-
suit
Returns the value of thesuitrecord component.- Returns:
- the value of the
suitrecord component
-