0

我正在尝试制作一个 Card 类来代表扑克牌。底部的代码运行顶部的代码。我只需要帮助开始。我不完全确定如何。我如何也为这个类创建构造函数?

public class Card
{
  public static final String FACES[] = {"ZERO","ACE","TWO","THREE","FOUR",
  "FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"};

//instance variables
    //String suit
    //int face

//constructors


// modifiers
    //set methods


//accessors
    //get methods


//toString

 }

public class CardRunner
{
    public static void main( String args[] )
    {
    Card one = new Card("SPADES", 9);
    out.println(one.getSuit());
    out.println(one.getFace());

    Card two = new Card("DIAMONDS", 1);
    out.println(two);
    two.setFace(3);
    out.println(two);

    Card three = new Card("CLUBS", 4);
    out.println(three);

    Card four = new Card("SPADES", 12);
    out.println(four);

    Card five = new Card("HEARTS", 12);
    out.println(five);
}
}
4

1 回答 1

4

我认为你应该在enum这里使用 forPlayingCard因为所有都是常量,你可以覆盖toString以提供有意义的表示。

如果创建枚举,则不必显式创建对象,并且可以在需要时使用枚举常量。您可以阅读关于为什么在 java 中使用枚举的很好的教程

于 2013-09-18T13:03:20.013 回答