我正在尝试编译这段代码,但它给了我一个错误,我不知道如何修复它。我正在尝试为 Go Fish 游戏编译 CardPile 类。
import java.util.Random;
public class CardPile {
enter code hereprivate Card[] cards;
private int numCards;
private static Random n = new Random(1);
public CardPile() {
this.numCards = 0;
this.cards = new Card[52];
}
public void addToBottom(Card c) {
this.cards[numCards] = c;
numCards++;
}
public Card removeCard(int ind) {
Card toRemove = this.cards[ind];
for (int i = ind; i < numCards - 1; i++) {
this.cards[i] = this.cards[i+1];
}
this.cards[numCards-1] = null;
numCards--;
return toRemove;
}
public Card removetop() {
Card topCard = cards[0];
Card[] cards = new Card[cards.length - 1];
int counter = 0;
for(int i = 1; i < cards.length; i++) {
cards[counter] = cards[i];
counter++;
}
this.cards = cards;
return topCard;
}
public int searchValue(int value) {
int count = 0;
for (int i = 0;i < cards.length;i++) {
if (cards(i) == value) { GIVES ME A CANNOT FIND SYMBOL HERE
count++;
}
}
return count;
}
public Card[] removeAll(int value) {
int count = searchValue(value);
Card[] removed = new Card[count];
for (int i = 0; i < cards.length;i++) {
[if (cards(i) != value) { GIVES ME A CANNOT FIND SYMBOL HERE
}
}
this.cards.toArray(removed); AND HERE AS WELL.
return removed;
}
public int getNumberCards() {
return this.numCards;
}
public String toString() {
String word = "";
for (int i = 0; i < numCards; i++) {
word = word + "[" + i + "]";
word = word + this.cards[i];
word = word + " ";
}
return word;
}
public void shuffle() {
for (int i = 0; i < 100000; i++) {
int first = n.nextInt(numCards);
int second = n.nextInt(numCards);
Card temp = this.cards[first];
this.cards[first] = this.cards[second];
this.cards[second] = temp;
}
}
public static CardPile makeFullDeck() {
CardPile deck = new CardPile();
for (int suit = 0;suit < 4;suit++) {
for (int value = 1; value < 14;value++) {
deck.addToBottom(new Card(suit, value));
}
}
deck.shuffle();
return deck;
}
}
我指出了我遇到问题的地方。
感谢您的帮助
最佳答案
使用括号代替..
cards(i)
至
cards[i]
关于java - CardPile 错误,无法编译。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29203464/