Original Post
I don''t understand why this code doesn''t work the way I think it''s supposed to.
public Card newCard (String c, String s) {
// pick a card outta the deck.
// match it with the selection given
// if not there, put it in the empty
// deck.
Card foundNewCard = null;
foundNewCard = NewDeck.remove();
for (int i = 0; i < NewDeck.size(); ++i) {
if (foundNewCard.getFace() == c && foundNewCard.getSuit() == s) {
return foundNewCard;
}
else {
EmptyDeck.placeCard(foundNewCard);
foundNewCard = NewDeck.remove();
}
}
}
But! this code works just fine.
public Card newCard (String c, String s) {
// pick a card outta the deck.
// match it with the selection given
// if not there, put it in the empty
// deck.
Card foundNewCard = null;
foundNewCard = NewDeck.remove();
for (int i = 0; i < NewDeck.size(); ++i) {
if (foundNewCard.getFace() == c && foundNewCard.getSuit() == s) {
break;
}
else {
EmptyDeck.placeCard(foundNewCard);
foundNewCard = NewDeck.remove();
}
}
return foundNewCard;
}
I had a problem similar to this before but with a switch statement. Could someone please tell me if I''m doing a programming no-no, if I am, tell why is it a no-no and what is the "official" rule??