Java 类型赋值器中的方法hasStraightCard[],int)不适用于参数(Card[]) package扑克; 公共类评估器{ 专用静态最终int MAX_卡=5; 专用静态最终整数最大值=13; 私人静态最终int MAX_SUIT=4; 专用静态int-totVal(卡[]卡,int值){ int-answer=0; 对于(INTA=0;a1&&!有四种(卡片); } 公共静态布尔类型(卡片[]卡片){ 返回总元组(卡片,3)>0; } **公共静态布尔hasStraight(卡片[]卡片,int开始){ 对于(int first=start;first

Java 类型赋值器中的方法hasStraightCard[],int)不适用于参数(Card[]) package扑克; 公共类评估器{ 专用静态最终int MAX_卡=5; 专用静态最终整数最大值=13; 私人静态最终int MAX_SUIT=4; 专用静态int-totVal(卡[]卡,int值){ int-answer=0; 对于(INTA=0;a1&&!有四种(卡片); } 公共静态布尔类型(卡片[]卡片){ 返回总元组(卡片,3)>0; } **公共静态布尔hasStraight(卡片[]卡片,int开始){ 对于(int first=start;first,java,Java,签名是hasStraight(Card[],int),但在hasStraightFlush()方法中您只调用hasStraight(Card[])。您还需要包含int值。问题在于代码的这部分: package poker; public class PokerHandEvaluator { private static final int MAX_CARDS=5; private static final int MAX_VAL=13; private static

签名是
hasStraight(Card[],int)
,但在
hasStraightFlush()
方法中您只调用
hasStraight(Card[])
。您还需要包含
int
值。

问题在于代码的这部分:

package poker;

public class PokerHandEvaluator {

    private static final int MAX_CARDS=5;
    private static final int MAX_VAL=13;
    private static final int MAX_SUIT=4;

    private static int totVal(Card[]cards, int value) {
        int answer=0;
        for(int a=0; a<MAX_CARDS; a++) {
            if(cards[a].getValue()==value) {
                answer++;
            }
        }
        return answer;
    }

    private static int totSuit(Card[]cards, int suit) {
        int answer=0;
        for(int a=0; a<MAX_CARDS; a++) {
            if(cards[a].getSuit()==suit) {
                answer++;
            }
        }
        return answer;
    }

    private static int totTuple(Card[]cards, int tupSize) {
        int answer=0;
        for(int a=1; a<MAX_VAL; a++) {
            if(totVal(cards,a)>=tupSize) {
                answer++;
            }
        }
        return answer;
    }

    public static boolean hasPair(Card[] cards) {
        return totTuple(cards,2)>0;
    }

    public static boolean hasTwoPair(Card[] cards) {
        return totTuple(cards,2)>1 && !hasFourOfAKind(cards);
    }

    public static boolean hasThreeOfAKind(Card[] cards) {
        return totTuple(cards,3)>0;
    }

    **public static boolean hasStraight(Card [] cards, int start) {
        for(int first=start; first<start+MAX_CARDS; first+=2) {
            int end=first+8;
            if(end==MAX_VAL+1) {
                end=1;
            }
            if(totVal(cards,first+0)==1 &&
                totVal(cards,first+2)==1 &&
                totVal(cards,first+4)==1 &&
                totVal(cards,first+6)==1 &&
                totVal(cards,end)==1) {
                return true;
            }**
        }
        return false;
    }

    public static boolean hasFlush(Card[] cards) {
        for(int a=0; a<MAX_SUIT; a++) {
            if(totSuit(cards,a)==MAX_CARDS) {
                return true;
            }
        }
                return false;
    }

    public static boolean hasFullHouse(Card[] cards) {
        boolean pokerPair=false;
        boolean pokerThree=false;
        for(int a=0; a<=MAX_VAL; a++) {
            int tot=totVal(cards,a);
            if(tot==2) {
                pokerPair=true;
            }
            if(tot==3) {
                pokerThree=true;
            }
        }
            return false;
    }

    public static boolean hasFourOfAKind(Card[] cards) {
        return totTuple(cards,4)>0;
    }

    **public static boolean hasStraightFlush(Card[] cards) {
        return(hasStraight(cards)&&(hasFlush(cards));
    }**
}

方法
hasStraight
需要两个参数:
Card[]
int
。您只需要传递其中的一个参数,还需要传递第二个参数,即int。

您定义了一个方法
hasStraight
,该方法包含两个参数,一个
Card[]
和一个
int
。然后您尝试在
hasStraightFlush
中仅用一个参数调用它

您需要同时传入这两个参数——否则Java怎么知道如何使用
int
值呢?在这种情况下,看起来您想要0,这样您就可以开始在手的开始处检查笔直(即,查看整只手是否笔直)


仔细查看
hasStraight()
函数的参数所需的内容。注意,您没有包括
int start
参数。
return(hasStraight(cards)&&(hasFlush(cards));
return(hasStraight(cards, 0)&&(hasFlush(cards));