Class Card

java.lang.Object
  extended by Card

public class Card
extends java.lang.Object

This Card class represents playing card. This class mainly has two attributes, those are Suit and Rank. When a Card object created, basically these two attibutes are assigned and and created. Basically, this class has been designed to fully feature card and its functions. In addition to this, a static function called newDeck() created a deck of cards and returns as an arraylist.


Nested Class Summary
static class Card.Rank
          Rank enum to name the card.
static class Card.Suit
          Suit enum to catogorise the card into main four types.
 
Field Summary
private static java.util.List<Card> protoDeck
           
private  Card.Rank rank
           
private  Card.Suit suit
           
 
Constructor Summary
Card(Card.Suit suit, Card.Rank rank)
          constructor of this card class, receives card suit and rank to create a card object
Card(java.lang.String card)
          constructor of this card class, receives card suit and rank as a single strings to create a card object
Card(java.lang.String suit, java.lang.String rank)
          constructor of this card class, receives card suit and rank strings to create a card object
 
Method Summary
 java.lang.String getImageName()
          returns the image name of a card which is saved in /resources/images/
static java.util.ArrayList<Card> newDeck()
          Returns a deck of cards as Arraylist.
 Card.Rank rank()
          returns rank of the card as Rank enum object.
 java.lang.String rank2string(Card.Rank rank)
          This method is to convert a Rank object to its name as String
 Card.Rank string2rank(java.lang.String rank)
          This method is to convert a String rank name to a real Rank object.
 Card.Suit string2suit(java.lang.String suit)
          This method is to convert a String suit name to a real Suit object.
 Card.Suit suit()
          returns suit of the card as Suit enum object.
 java.lang.String suit2string(Card.Suit suit)
          This method is to convert a Suit object to its name as String
 java.lang.String toString()
          returns a String value of a card.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

suit

private final Card.Suit suit

rank

private final Card.Rank rank

protoDeck

private static final java.util.List<Card> protoDeck
Constructor Detail

Card

public Card(Card.Suit suit,
            Card.Rank rank)
constructor of this card class, receives card suit and rank to create a card object


Card

public Card(java.lang.String suit,
            java.lang.String rank)
constructor of this card class, receives card suit and rank strings to create a card object

Parameters:
suit - a card suit's name as String
rank - a card rank's name as String

Card

public Card(java.lang.String card)
constructor of this card class, receives card suit and rank as a single strings to create a card object

Parameters:
card - a card suit's name and rank's name as a single String. Eg: JACK of HEARTS
Method Detail

string2rank

public Card.Rank string2rank(java.lang.String rank)
This method is to convert a String rank name to a real Rank object.

Parameters:
rank - name of a card rank as String
Returns:
Rank

string2suit

public Card.Suit string2suit(java.lang.String suit)
This method is to convert a String suit name to a real Suit object.

Parameters:
suit - name of a card suit as String
Returns:
Suit

rank2string

public java.lang.String rank2string(Card.Rank rank)
This method is to convert a Rank object to its name as String

Parameters:
rank - Rank object of a card.
Returns:
String name of the Rank object

suit2string

public java.lang.String suit2string(Card.Suit suit)
This method is to convert a Suit object to its name as String

Parameters:
suit - Suit object of a card.
Returns:
String name of the Suit object.

rank

public Card.Rank rank()
returns rank of the card as Rank enum object.


suit

public Card.Suit suit()
returns suit of the card as Suit enum object.


getImageName

public java.lang.String getImageName()
returns the image name of a card which is saved in /resources/images/


toString

public java.lang.String toString()
returns a String value of a card. Eg: TEN of HEARTS

Overrides:
toString in class java.lang.Object

newDeck

public static java.util.ArrayList<Card> newDeck()
Returns a deck of cards as Arraylist. This arraylist is implemented in java util package.