if(hand1.get(0).compareTo(hand1.get(1)== 1))
Here you're comparing hand1.get(0)
, which is the first alement of the list of cards, and is thus a card, with hand1.get(1)== 1
. What you want is
if (hand1.get(0).compareTo(hand1.get(1)) > 0)
(because a comparison can return any positive number to mean first > second
).
else if (hand1.get(0).compareTo(1)==-1)
And not you're comparing hand1.get(0), which is the first alement of the list of cards, and is thus a card, with
1`, which is an int. It doesn't make sense either. You want
else if (hand1.get(0).compareTo(hand1.get(1)) < 0)
Also, note that yoy should use generics for your class. It should be declared as a Comparable<card>
, and not as a raw Comparable
:
public class card implements Comparable<card>
public int compareTo(card other) {
...
}
}
And of course, it should also respect the Java naming conventions: classes start with an uppercase letter:
public class Card implements Comparable<Card>
public int compareTo(Card other) {
...
}
}