Package cs171a2

Class Card

java.lang.Object
cs171a2.Card

public class Card extends Object
A class that represents a playing card with a rank and suit.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The identifier of the card.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Card(int suit, int rank)
    Creates a new Card with the given suit and rank.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the rank of the card.
    int
    Gets the suit of the card.
    void
    setRank(int rank)
    Sets the rank of the card.
    void
    setSuit(int suit)
    Sets the suit of the card.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • identifier

      public final int identifier
      The identifier of the card. It is a unique number assigned to each card based on its rank and suit. The identifier is calculated as suit * 100 + rank.
  • Constructor Details

    • Card

      public Card(int suit, int rank)
      Creates a new Card with the given suit and rank. It assigns the identifier as well
      Parameters:
      suit - The suit of the card.
      rank - The rank of the card.
  • Method Details

    • getRank

      public int getRank()
      Gets the rank of the card.
      Returns:
      The rank of the card.
    • setRank

      public void setRank(int rank)
      Sets the rank of the card.
      Parameters:
      rank - The new rank of the card.
    • getSuit

      public int getSuit()
      Gets the suit of the card.
      Returns:
      The suit of the card.
    • setSuit

      public void setSuit(int suit)
      Sets the suit of the card.
      Parameters:
      suit - The new suit of the card.