已经有一个名为 Card.java 的类有 52 张卡片。在 Deck.java 中,我必须编写一个构造函数来用套件和值连续初始化 52 张卡。我写了下面的代码,但它没有通过公共测试..有人可以帮我吗?
public class Deck {
private Card[] cards;
private final int DECK_SIZE=52;
public Deck(){
this.cards=new Card[DECK_SIZE];
int index = 0;
for (int suit = 0; suit <= 3; suit++) {
for (int value = 1; value <= 13; value++) {
this.cards[index] = new Card (suit, value);
index++;
}
}
}
public Deck(Deck other) {
this.cards= new Card[DECK_SIZE];
for(int i=1;i<=DECK_SIZE;i++){
this.cards[i]= other.cards[i];
}