public class Team{ private int numWins; private int strength; private String name; private Team team; /** * Constructor for Team Objects * * @param name name of team * @param numWins number of wins in regular season * @param strength strength of schedule for this team */ public Team( String name, int numWins, int strength ){ this.name = name; this.numWins = numWins; this.strength = strength; } /** * Returns true if two teams are identical * * @param other a second team, used to test for equality * @return true if other is a Team object, and both objects * contain the same value for all instance variables. */ public boolean equals( Object other ){ boolean value = false; if( ( team = new Team( name, numWins, strength )).equals( other ) ){ value = true; } return value; } /** * compareTo provided to allow sorting of Team Objects * * @param other a second team, used to compare number of wins * @return returns a 1 if the current team has fewer wins than the * other team; -1 if the current team has more wins. If two * teams have the same number of wins, compare using strength * of schedule: return 1 if the current team has a smaller * strength than the other team. Return -1 if the current * team has a greater strength. If two teams have the same * number of wins and strength, compare using the natural * order comparison of the current team name compared to * the other team name. */ public int compareTo( Team other ){ int value = 0; if( numWins > other.getWins() ){ value = -1; } else if( numWins < other.getWins() ){ value = 1; } else{ if( strength > other.getStrengthOfSchedule() ){ value = -1; } else if( strength < other.getStrengthOfSchedule() ){ value = 1; } else{ value = name.compareTo( other.getTeamName() ); } } return value; } /** * Accessor method for team name * * @return team name */ public String getTeamName(){ return name; } /** * Accessor method for number of wins for this team * * @return the number of wins */ public int getWins(){ return numWins; } /** * Accessor method for the strength of schedule for this team * * @return the strength of schedule */ public int getStrengthOfSchedule(){ return strength; } /** * A simple implemntation of toString() * * @return a string representation of this team. The format is * "team: (team-name) has: (#wins) wins under a schedule * whose strength was rated: (strength) out of 10." */ public String toString(){ String print = "team: " + getTeamName() + " has: " + getWins() + " wins under a schedule whose strength was rated: " + getStrengthOfSchedule() + " out of 10."; return print; } } // Team