java - CardPile 错误,无法编译。

标签 java javascript

我正在尝试编译这段代码,但它给了我一个错误,我不知道如何修复它。我正在尝试为 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/

相关文章:

javascript - 同时为每个div添加不同的变量

java - 如何在 Android 上以编程方式创建断点

java - 用 listIterator 替换 ArrayList 中的项目 - 无法解决 listIterator.set()

java - 寻找最近的点

java - StAX 返回未知案例

javascript - 在 blogger Post 中添加 javascript

java - 如何比较文本文件的每一行? java

javascript - 在 JavaScript 中,在运行时向对象添加属性和函数的名称是什么?

javascript - 如何使用javascript获取div的值

javascript - 如何通过两行的数量来限制我的标题?