Created
January 30, 2014 03:09
-
-
Save Nocsaron/8701841 to your computer and use it in GitHub Desktop.
Card.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package poker; | |
public class Card implements Comparable<Card> { | |
private Rank card_rank; | |
private Suit card_suit; | |
public Card(Rank card_rank, Suit card_suit) { | |
this.card_rank = card_rank; | |
this.card_suit = card_suit; | |
} | |
public int compareTo(Card other) throws DuplicateCardException { | |
if(card_rank == other.getRank() && card_suit == other.getSuit()) | |
throw new DuplicateCardException(); | |
if(card_rank.getValue() == other.getRank().getValue()) { return 0; } | |
else if(card_rank.getValue() < other.getRank().getValue()) { return -1; } | |
else if(card_rank.getValue() > other.getRank().getValue()) { return 1; } | |
return -2; | |
} | |
public Rank getRank() { | |
return card_rank; | |
} | |
public Suit getSuit() { | |
return card_suit; | |
} | |
public String toString() { | |
return(card_suit + "" + card_rank); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment