So I have a lab (we are allowed to seek outside help on it, so here I am after lots of head scratching) where we have to implement a deck of cards. We have to use the enum class to create num
For Suits:
public enum Suits {
CLUBS, HEARTS, DIAMONDS, SPADES
}
For Numerals:
public enum Numerals {
DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9),
TEN(10), JACK(11), QUEEN(12), KING(13), ACE(14);
}
My card class is pretty straightforward, but I'm not sure about these two blocks of code:
public int compareTo (Card aCard){
if (aCard.aNumeral.equals(this.aNumeral) && aCard.aSuit.equals(this.aSuit)){
return 0;
}
else {
return -1;
}
}
and
public boolean equals (Card aCard){
if (this.compareTo(aCard) == 0){
return true;
}
else {
return false;
}
}
Now for the tricky part...the Deck...
So we have to implement the deck using Cloneable, Iterable and Comparator, so here is what I have so far and just can't figure out what to.
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
public class Deck implements Cloneable, Iterable<Card>, Comparator<Card> {
private ArrayList<Card> cards;
public Deck (){
for (Card c : cards){
}
}
I'm struggling to even put together the constructor. I'm planning on using an ArrayList to essentially "hold" 52 sorted cards (as you can see); but we have to ultimately return a sorted deck. Any suggestions on where to go?