My method is supposed to return a Card, I have an if statement within a for loop - I don't want to add 'return c' at the end, as that will return the last Card in carddeck. I'm getting errors saying "must return type Card". What would you advise?
P.S. this is one of my first posts - apologies if it has an obvious answer. All these brackets are putting me off...
public Card findRightCardWithIndex(int index) throws IllegalArgumentException {
for(Card c:carddeck) {
if (c.getIndex() == index) {
return c;
} else {
throw new IllegalArgumentException("Invalid index");
}
}
}
Aucun commentaire:
Enregistrer un commentaire