Java 我的程序在另一个类中找不到已定义的方法

Java 我的程序在另一个类中找不到已定义的方法,java,Java,定义方法的My card类 package blackjackgamemodel; public class Card { protected Rank rank; protected Suit suit; public Card(Card.Rank rank, Card.Suit suit) { this.rank = rank; this.suit = suit; } public String toString(

定义方法的My card类

package blackjackgamemodel;

public class Card {
    protected Rank rank;
    protected Suit suit;

    public Card(Card.Rank rank, Card.Suit suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public String toString() {
        return "" + rank + " of " + suit;
    }

    public Card.Rank rank() {
        return rank;
    }

    public Card.Suit suit() {
        return suit;
    }

    public enum Rank {
        ACE (1), TWO (2), THREE (3), FOUR (4), FIVE (5), SIX (6), SEVEN (7),
        EIGHT (8), NINE (9), TEN (10), JACK (11), QUEEN (12), KING (13);

        private int value;

        Rank(int value) {
            this.value = value;
        }

        public int value() {
            return value;
        }
    }

    public enum Suit {
        SPADES, HEARTS, CLUBS, DIAMONDS
    }

}
错误所在的游戏类

package blackjackgamemodel;

import blackjackgamemodel.Card;
import blackjackgamemodel.Deck;

public class Game {
    protected Deck deck;
    protected int sum;
    protected int aces;


    public Game() {
        // Initialize deck, sum and aces.
        deck = new Deck();
        sum = 0;
        aces = 0;
    }

    public Card draw() {

        // Draw a card from the deck
        Card drawn_card = deck.draw();

        // Calculate the value to add to sum
        int v = drawn_card.value();
        if (v == 1) {
            v = 11;
            // If the card is an ace, increase the count of aces.
            aces++;
        }
        else if (v > 10) {
            v = 10;
        }
        // Now v is the Blackjack value of the card.

        // If the sum is greater than 21 and there are aces,
        //   Then decrease the sum by 10 and the aces by 1.
        if (aces > 0 && sum > 21) {
            sum = sum - 10;
            aces = aces - 1;
        }

        // Return the card that was drawn.
    return drawn_card; 

    }

    public int sum() {
        // Getter for sum.
        return sum;

    }
}
错误


具有
value()
方法的是
Card.Rank
enum,而不是
Card

尝试:


具有
value()
方法的是
Card.Rank
enum,而不是
Card

尝试:


确实
没有
方法:它有
方法和
卡。秩
方法。

确实
没有
方法:它有
方法和
卡。秩
方法。

你的卡有值吗方法?看起来卡的等级有一个值方法

尝试:


你的卡有计价方法吗?看起来卡的等级有一个值方法

尝试:


value()
不是
Card
上的方法,而是在
卡上。在您的包含代码中排名

value()
不是
卡上的方法,而是在
卡上。在您的包含代码中排名

消息是正确的,卡上没有value()方法。你的意思是得到卡的等级然后得到那个值吗?这看起来像是故意的

消息正确,卡没有value()方法。你的意思是得到卡的等级然后得到那个值吗?这看起来像是故意的

谢谢:)现在它抽走了牌组中的每一张牌,但没有增加总数。谢谢:)现在它抽走了牌组中的每一张牌,但没有增加总数
Description Resource    Path    Location    Type
The method value() is undefined for the type Card   Game.java   /BlackJack/src/blackjackgamemodel   line 25 Java Problem
int v = drawn_card.rank().value()
int v = drawn_card.rank().value();