FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

ScoreComparator.java




A Java program included in my Sungka package.

Code:

//Declare package
package htwx.cay;

//Import classes
import java.util.Comparator;

/**
 *<p><strong>ScoreComparator</strong> - Class that can be used to compare scores of type Player.
 * This class contains 1 method, namely: compare().
 * Read further to see more in detail.</p>
 *<p>See {@link HighscoreManager} for instantiation.</p>
 * @author Acezon Cay
 */
public class ScoreComparator implements Comparator<Player> {
   /**
    * compare() Used to compare to scores of type Player.
    * @param score1 Data of type Player.
    * @param score2 Data of type Player.
    * @return {@code -1, 1 or 0} : -1 if {@code score1} > {@code score2}, 1 if {@code score1} < {@code score2} and 0 if scores are equal.
    */
   public int compare(Player score1, Player score2) {
        int sc1 = score1.getScore();
        int sc2 = score2.getScore();
               
        if (sc1 > sc2) {
            return -1;
        }
        else if (sc1 < sc2) {
            return 1;
        }
        else {
            return 0;
        }
   }
}




0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.