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 public class Tournament { /** * maximum number of teams permitted in a tournament; currently * set to 64 */ public static final int MAX_TEAMS = 64; /** * actual number of teams entered in this tournament */ private static int numberOfTeams; /** * The main program. * * @param args command line arguments * * @exception IOException may have propagated back from * TournamentMaker */ public static void main(String[] args ) throws IOException { numberOfTeams = Integer.parseInt( args[ 0 ] ); if ( numberOfTeams < MAX_TEAMS && ( numberOfTeams == 4 || numberOfTeams == 8 || numberOfTeams == 16 || numberOfTeams == 32 || numberOfTeams == 64 ) ) { TournamentMaker tournament = new TournamentMaker(); tournament.make( numberOfTeams ); } else { System.err.print( "Number of teams must be > 2 and <= " + MAX_TEAMS ); System.err.println( " and be a power of 2." ); } } }