import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 *
 * @author davereed
 */
public class ScoresList {
    private Map<String, WinLossRecord> scores;
    
    public ScoresList() {
        this.scores = new TreeMap<String, WinLossRecord>();
    }
    
    public void recordScore(String team1, int score1, 
                            String team2, int score2) {
        if (!this.scores.containsKey(team1)) {
            this.scores.put(team1, new WinLossRecord(team1));
        }
        if (!this.scores.containsKey(team2)) {
            this.scores.put(team2, new WinLossRecord(team2));
        }
        
        if (score1 > score2) {
            this.scores.get(team1).addWin();
            this.scores.get(team2).addLoss();
        }
        else {
            this.scores.get(team2).addWin();
            this.scores.get(team1).addLoss();            
        }
        
    }
    
    public void displayScores() {
        TreeSet<WinLossRecord> recs = new TreeSet<WinLossRecord>();
        for (String team : this.scores.keySet()) {
            recs.add(this.scores.get(team));
        }

        for (WinLossRecord nextRec : recs) {
            System.out.println(nextRec);
        }
    }
    
    public static void main(String[] args) {
        ScoresList intramurals = new ScoresList();
        
        intramurals.recordScore("Cougars", 72, "Cows", 45);
        intramurals.recordScore("Slugs", 44, "Cows", 45); 
        
        intramurals.displayScores();
        
    }
}
