Reputation: 331
I am trying to read in a user input as a string. Parse it into an int, then whatever number (0-3) that the user input, I want to replace that index of the array with a card. Here is the code
public void discard(String text) {
int i = Integer.parseInt(text);
for(int p = 0; p < 4; p++){
if(i == p){
hand[p].getCard() = card; // This is where I recieve the Error.
}
}
}
Anything that will help me correct and understand my mistake will be helpful, Thanks!
Upvotes: 0
Views: 96
Reputation: 425198
Without seeing your code, you're probably going to to need to change:
hand[p].getCard() = card;
to
hand[p].setCard(card);
You can't assign to a getter.
Also, this code:
for (int p = 0; p < 4; p++) {
if (i == p){
// do something with p
}
}
Can be replaced with
// do something with i
Upvotes: 0
Reputation: 45070
I think you meant to do this
hand[p].setCard(card);
because the below piece of code doesn't really make sense. You can't possibly assign a value to a value(retrieved by getCard()
) method. That is why you got the error that it expected a variable on the left hand side of the assignment operator, but instead found a String there.
hand[p].getCard() = card;
Upvotes: 5