Using the Card class below, add the code to have the Cards sorted by suite and then
Question:
Using the Card class below, add the code to have the Cards sorted by suite and then denim. Your solution should check for invalid objects and throw an exception if an illegal object is passed.
public class Card implements Comparable
// Comparators by suit and by denomination
public static final Comparator
public static final Comparator
// Suit of the card (CLUBS = 1, DIAMONDS = 2, HEARTS = 3, SPADES = 4)
private final int suit;
// Denomination of the card
private final int denom;
public Card(int suit, int denom) {
if (suit < 1 || suit > 4)
throw new IllegalArgumentException("Invalid suit");
if (denom < 1 || denom > 13)
throw new IllegalArgumentException("Invalid denomination");
this.suit = suit;
this.denom = denom;
}
// COMPLETE THE FOLLOWING FUNCTION
public int compareTo(Object o) {
/*
* YOUR CODE HERE
*/
return 0;
}
}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill