我正在写一份家庭作业,创造了一整套52张牌。我在第18行遇到了一些问题。
hearts[x].setSuit("Hearts");
以下是代码的其余部分:
public class FullDeck
{
public static void main(String[] args)
{
//Creates four arrays for each deck
Card[] hearts = new Card[13];
Card[] clubs = new Card[13];
Card[] spades = new Card[13];
Card[] diamonds = new Card[13];
//Fills the hearts deck
for(int x = 0; x < hearts.length; ++x)
{
hearts[x].setSuit("Hearts");
hearts[x].setValue(x+1);
System.out.println("The " + hearts[x].getRank() + " of " + hearts[x].getSuit());
}
}
}
卡类型的客户端类:
public class Card
{
private String suit;
private int value;
private String rank;
public String getSuit()
{
return suit;
}
public int getValue()
{
return value;
}
public String getRank()
{
return rank;
}
public void setSuit(String s)
{
suit = s;
}
public void setValue(int v)
{
final int LOW = 1;
final int HIGH = 13;
if(v >= LOW && v <= HIGH)
value = v;
else
value = LOW;
if(value == 1)
rank = "Ace";
else
if(value == 11)
rank ="Jack";
else
if(value == 12)
rank = "Queen";
else
if(value == 13)
rank = "King";
else
rank = Integer.toString(value);
}
}
如果我能得到一个详细的解释,那么到底出了什么问题将非常感激:)。我也不熟悉java编码,所以任何来自那里的退伍军人的提示都会受到关注,谢谢!