how to use Comparator in a card game
<p>For homework I was given the following code with the methods in blank. I have been working on it,but I still do not understand how the mutator setComparer or the Comparator comparer work in this program. I have researched online how to use Comparators,but the idea is still unclear. Can anyone give me some kind of guidance?.</p>

<ol>
<li>Do I have to initialize Comparator comparer? if so, how do I do it?</li>
<li>what do the comments above private int compare(PlayingCard one, PlayingCard two) mean?(this.comparer=null)</li>
</ol>

<p>Thanks</p>

<pre><code>import java.util.*;
//Class to represent a "generic" hand of playing-cards
public class PlayingCardHand {
//Instance Variables

private int cardsInCompleteHand;     //Maximum # cards in this hand
private ArrayList&lt;PlayingCard&gt; hand; //A hand of Playing-Cards
private Comparator comparer;         //Client-provided comparison of PlayingCards

//Constructor
//Appropriate when PlayingCard compareTo() is to be used to compare PlayingCards
public PlayingCardHand(int handSize) {
    cardsInCompleteHand = handSize;
    hand = new ArrayList&lt;PlayingCard&gt;();

}

//Helper: Compare 2 PlayingCards
// if this.comparer is null, comparison uses compareTo()
//                           otherwise the Comparator is applied
private int compare(PlayingCard one, PlayingCard two) {

    return 0;
}

//Accessor: return # of cards currently in this hand
public int getNumberOfCards() {
    return cardsInCompleteHand;
}

public boolean isComplete() {
    if (hand.size() == cardsInCompleteHand) {
        return true;
    }
    return false;
}

//Accessor: return COPIES of the cards in this hand
public PlayingCard[] getCards() {
    PlayingCard[] temp = new PlayingCard[hand.size()];

    for (int i = 0; i &lt; hand.size(); i++)//ch
    {

        temp[i] = hand.get(i);
    }
    return temp;
}

//Mutator: allows a client to provide a comparison method for PlayingCards
public void setComparer(Comparator comparer) {
}

//Mutator: Append a new card to this hand
public void appendCard(PlayingCard card) {
    int counter = 0;
    PlayingCard.Suit su = card.getSuit();
    PlayingCard.Rank ra = card.getRank();

    PlayingCard temp3 = new PlayingCard(su, ra);

    //10 20 goes here 30 40 if insert 25
    for (int i = 0; i &lt; hand.size(); i++) {
        PlayingCard temp4 = hand.get(i);
        PlayingCard.Suit sui = temp4.getSuit();
        PlayingCard.Rank ran = temp4.getRank();
        if (su.ordinal() &lt;= sui.ordinal() &amp;&amp; ra.ordinal() &lt;= ran.ordinal()) {
            hand.add(i, temp3);
            counter++;
        }

    }
    while (counter == 0) {
        hand.add(temp3);
    }
}
</code></pre>
