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
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;
}
}
Step by Step Solution
3.48 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
Updated Card class with the compareTo method implemented to achieve the desired sorting import javau...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started