我正在尝试创建一个创建一副 52 张卡片的程序。当我尝试编译代码时,它一直说“无法在 createDeck 方法中的所有 getName getter 上找到符号。我是 Java 编程新手,所以我不知道该怎么做。任何建议都是有帮助。这是代码:
public class Card {
private int value;
private String name;
private String suit;
public void setValue(int v){
value = v;
}
public int getValue(){
return value;
}
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public void setSuit(String s){
suit = s;
}
public String getSuit(){
return suit;
}
}
这个类应该创建一个甲板:
public class cardDeck {
int[] values = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
String[] names = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "King", "Queen", "Jack", "Ace",};
String[] suits = {"Clubs", "Spades", "Hearts", "Diamonds"};
public Card[] createDeck (Card[] d){
for(int j:deck){
d[j] = new Card();
for(String k:names){
d[j].setName(k);
}
for(int i:values){
if((d[j].getName == ("King")) || (d[j].getName == ("Queen")) || (d[j].getName == ("Jack"))){
d[j].setValue(10);
}else if(d[j].getName == ("Ace")){
d[j].setValue(11);
}else{
d[j].setValue(i);
}
}
for(String l:suits){
d[j].setSuit(l);
}
}
return d;
}
}
这是测试器类:
class CardTest {
public static void main(String[] args){
Card[] deck = new Card[52];
cardDeck playingCards = new cardDeck();
playingCards.createDeck(deck);
for(int q = 0; q < 52; q++){
System.out.println(deck[q]);
}
}
}