import java.util.*; /* Players one and two each try to solve a maze by drawing a path through it; the shorter path wins each time. The GameTracker keeps track of these wins; playAGame() gets passed their paths, and uses the StringLengthComparator to pick the shorter one. But we could use a different Comparator as well; we could specify, for instance, that passing through certain cells of the maze earns extra points - in that case, we'd write a different Comparator that checks for these special cells. */ public class GameTracker { private Comparator comparer; private int playerOneWins; private int playerTwoWins; private int ties; public GameTracker(Comparator c) { comparer = c; playerOneWins = 0; playerTwoWins = 0; ties = 0; } public void playAGame(E onesPath, E twosPath) { int result = comparer.compare(onesPath,twosPath); if(result < 0) playerOneWins++; else if(result > 0) playerTwoWins++; else ties++; } public static void main(String[] args) { Comparator c=new StringLengthComparator(); GameTracker gt=new GameTracker(c); //... //run some games } }