If your reading this...thanks!
ok...so I'm trying to add a method that is supposed to return a value based on the poker rank of a hand of cards.0 for the lowest hand(no hand that is) and 10 for the highest hand(royal flush). I have already defined 5 .java source files(2 enum, 3 class) that are desinged to create a deck.
i have 2 main problems:
1. Which class do I put the method in?
2. How exactly do i design this method?
If some one could help me i would really appreciate it!
Here are the classes:
Suit.java
public enum Suit {
CLUBS, DIAMONDS, HEARTS, SPADES
}
Rank.java
public enum Rank {
TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT,
NINE, TEN, JACK, QUEEN, KING, ACE
}
Card.java
public class Card implements Comparable<Card> {
//compare two cards
public int compareTo(Card card) {
if(suit.equals(card.suit)) {
if(rank.equals(card.rank)) {
return 0;
}
return rank.compareTo(card.rank) < 0 ? -1 : 1;
} else {
return suit.compareTo(card.suit) < 0 ? -1 : 1;
}
}
public String toString() {
return rank + " of " + suit;
}
public Card(Rank rank, Suit suit) {
this.suit = suit;
this.rank = rank;
}
public Suit getSuit() {
return suit;
}
public Rank getRank() {
return rank;
}
private Rank rank;
private Suit suit;
}
Hand.java
import java.util.Vector;
import java.util.Collections;
public class Hand {
public Hand sort() {
Collections.sort(hand);
return this;
}
//add card to hand
public void add(Card card) {
hand.add(card);
}
public String toString() {
StringBuilder str = new StringBuilder();
for(Card card : hand) {
str.append("\n" + card);
}
return str.toString();
}
private Vector<Card> hand = new Vector<Card>();
}
CardDeck.java
import java.util.Stack;
import java.util.Collections;
public class CardDeck {
//create a deck of 52 cards
public CardDeck() {
for(Suit suit : Suit.values())
for(Rank rank : Rank.values())
deck.push(new Card(rank, suit));
}
//deal a hand
public Hand dealHand(int numCards) {
Hand hand = new Hand();
for(int i = 0; i < numCards; i++) {
hand.add((Card)deck.pop());
}
return hand;
}
//shuffle deck
public void shuffle() {
Collections.shuffle(deck);
}
private Stack<Card> deck = new Stack<Card>();
}
if you have any questions here's my e-mail:
[email protected]
IronChef -
http://www.freewebs.com/cool_recipes