I have two simple classes, Card
and CardTester
. One of the methods in Card
checks to see if two cards are equal to one another.
However, when using calling the method matches()
in CardTester
, it returns false
, when it should return true
.
public class Card {
private String rank;
private String suit;
private int val;
public Card(String cardrank, String cardsuit, int cardval) {
rank = cardrank;
suit = cardsuit;
val = cardval
}
public boolean matches(Card a) {
if (this.val == a.val && this.suit == a.suit && this.val == a.val) {
return true;
}
else {
return false;
}
}
Calling the method in another class:
public static void main(String[] args){
Card c2 = new Card("king", "clubs", 10);
Card c3 = new Card("king", "clubs", 10);
if (c2.equals(c3)) {
System.out.println("Cards are equal");
}
else {
System.out.println("Cards aren't equal");
}
The output ends up being "Cards aren't equal" when it should be "Cards are equal".