这里需要一些帮助。我怎样才能让牌组显示出来。似乎无法让它们显示出来。继续说Card
为空。使用Main
文件调用displayDeck
方法。
public class deck {
public Card[] deck;
public void CreateDeck(){
Card[] deck = new Card[52];
String[] suit = {"Spades", "Hearts", "Diamonds", "Clubs"};
int[] number = {1,2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13};
deck[0] = new Card("Spades",1);
deck[1] = new Card("Spades",2);
deck[2] = new Card("Spades",3);
deck[3] = new Card("Spades",4);
deck[4] = new Card("Spades",5);
deck[5] = new Card("Spades",6);
deck[6] = new Card("Spades",7);
deck[7] = new Card("Spades",8);
deck[8] = new Card("Spades",9);
deck[9] = new Card("Spades",10);
deck[10] = new Card("Spades",11);
deck[11] = new Card("Spades",12);
deck[12] = new Card("Spades",13);
deck[13] = new Card("Clubs",1);
deck[14] = new Card("Clubs",2);
deck[15] = new Card("Clubs",3);
deck[16] = new Card("Clubs",4);
deck[17] = new Card("Clubs",5);
deck[18] = new Card("Clubs",6);
deck[19] = new Card("Clubs",7);
deck[20] = new Card("Clubs",8);
deck[21] = new Card("Clubs",9);
deck[22] = new Card("Clubs",10);
deck[23] = new Card("Clubs",11);
deck[24] = new Card("Clubs",12);
deck[25] = new Card("Clubs",13);
deck[26] = new Card("Heart",1);
deck[27] = new Card("Heart",2);
deck[28] = new Card("Heart",3);
deck[29] = new Card("Heart",4);
deck[30] = new Card("Heart",5);
deck[31] = new Card("Heart",6);
deck[32] = new Card("Heart",7);
deck[33] = new Card("Heart",8);
deck[34] = new Card("Heart",9);
deck[35] = new Card("Heart",10);
deck[36] = new Card("Heart",11);
deck[37] = new Card("Heart",12);
deck[38] = new Card("Heart",13);
deck[39] = new Card("Diamonds",1);
deck[40] = new Card("Diamonds",2);
deck[41] = new Card("Diamonds",3);
deck[42] = new Card("Diamonds",4);
deck[43] = new Card("Diamonds",5);
deck[44] = new Card("Diamonds",6);
deck[45] = new Card("Diamonds",7);
deck[46] = new Card("Diamonds",8);
deck[47] = new Card("Diamonds",9);
deck[48] = new Card("Diamonds",10);
deck[49] = new Card("Diamonds",11);
deck[50] = new Card("Diamonds",12);
deck[51] = new Card("Diamonds",13);
}
public void displayDeck(){
for (int i =0;i<=50;i++){
System.out.println("Card " + (i+1)+ " is: " + deck)// display deck;
}
}
}
答案 0 :(得分:0)
你要覆盖你的变量&#34; deck&#34;在您的构造函数中,而不是使用您的公共属性。
public void CreateDeck(){
//Before
//Card[] deck = new Card[52];
//Correction
deck = new Card[52];
String[] suit = {"Spades", "Hearts", "Diamonds", "Clubs"};
int[] number = {1,2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13};
deck[0] = new Card("Spades",1);
deck[1] = new Card("Spades",2);
deck[2] = new Card("Spades",3);
deck[3] = new Card("Spades",4);
...
}