10 date 2008.04.15.21.32.14; author rmh3093; state Exp;
15 date 2008.04.10.19.15.31; author rmh3093; state Exp;
27 @make tourney properly
34 * $Id: Team.java,v 1.1 2008/04/10 19:15:31 rmh3093 Exp rmh3093 $
38 * Revision 1.1 2008/04/10 19:15:31 rmh3093
44 * This class represents a team that participates in a league. For each team, we
45 * record its name, the number of wins the team has during the "regular" season,
46 * and an indicator that provides some measure of the strength of this team's
52 public class Team implements Comparable<Team> {
59 * Constructor for Team objects
61 * @@param name name of team
62 * @@param numWins number of wins in regular season
63 * @@param strength strength of schedule for this team
65 public Team(String name, int numWins, int strength) {
67 this.numWins = numWins;
68 this.strength = strength;
72 * returns true if two teams are identical
74 * @@param other a second team, used to test for equality
75 * @@return true if other is a Team object, and both objects contain the
76 * same value for all instance variables.
78 public boolean equals(Object other) {
80 if ( other.getClass().getSimpleName().compareTo("Team") == 0 ) {
81 if (((Team)other).name.compareTo(this.name) == 0 ) {
82 if (((Team)other).numWins == this.numWins) {
83 if (((Team)other).strength == this.strength) {
93 * compareTo provided to allow sorting of Team objects
95 * @@param other a second team, used to compare number of wins
96 * @@return returns a 1 if the current team has fewer wins than the 'other'
97 * team; returns a value of -1 if the current team has more wins than the
98 * 'other' team. If two teams have the same number of wins, compare using
99 * strength of schedule: returns a value of 1 if the current team has a
100 * smaller strength of schedule than the 'other' team; returns a value of -1
101 * if the current team has a greater strength of schedule than the 'other'
102 * team. If two teams have the same number of wins and the same strength of
103 * schedule, compare using the natural order comparison of the the current
104 * team name compared to the 'other' team name.
106 public int compareTo(Team other) {
108 if (this.numWins < other.numWins) {
110 } else if (this.numWins > other.numWins) {
113 if (this.strength < other.strength) {
115 } else if (this.strength > other.strength) {
118 char[] thisName = this.name.toCharArray();
119 char[] otherName = other.name.toCharArray();
120 for (int i=0; i<thisName.length; i++) {
121 if ( thisName[i] < otherName[i] ) {
124 } else if ( thisName[i] > otherName[i] ) {
135 * accessor method for team name
137 * @@return returns team name
139 public String getTeamName() {
144 * accessor method for number of wins for this team
146 * @@return returns the number of wins
148 public int getWins() {
153 * accessor method for the strength of schedule for this team
155 * @@return returns the strength of schedule
157 public int getStrengthOfSchedule() {
158 return this.strength;
162 * a simple implementation of 'toString()'
164 * @@return returns a String representation of this team. The format is:
165 * "team: (team-name) has: (# wins) wins under a schedule whose strength was
166 * rated: (strength) out of 10."
168 public String toString() {
169 return "team: " + this.name + " has: " + this.numWins + " wins " +
170 "under a schedule whose strength was rated: " + this.strength +
190 if (this.strength < other.numWins) {
193 } else if (this.strength > other.numWins) {