kashdkjaf
[rmh3093.git] / lab5 / act2 / RCS / Team.java,v
blobd7521550b189f9682418479842a8fe2b9329f505
1 head    1.2;
2 access;
3 symbols;
4 locks
5         rmh3093:1.2; strict;
6 comment @# @;
9 1.2
10 date    2008.04.15.21.32.14;    author rmh3093; state Exp;
11 branches;
12 next    1.1;
14 1.1
15 date    2008.04.10.19.15.31;    author rmh3093; state Exp;
16 branches;
17 next    ;
20 desc
21 @working version
25 1.2
26 log
27 @make tourney properly
29 text
30 @/*
31  * Team.java
32  *
33  * Version:
34  *     $Id: Team.java,v 1.1 2008/04/10 19:15:31 rmh3093 Exp rmh3093 $
35  *
36  * Revisions:
37  *     $Log: Team.java,v $
38  *     Revision 1.1  2008/04/10 19:15:31  rmh3093
39  *     Initial revision
40  *
41  */
43 /**
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 
47  * schedule.
48  *  
49  * @@author Ryan Hope
50  *
51  */
52 public class Team implements Comparable<Team> {
53         
54         private String name;
55         private int numWins;
56         private int strength;
57         
58         /**
59          * Constructor for Team objects
60          *  
61          * @@param name name of team
62          * @@param numWins number of wins in regular season
63          * @@param strength strength of schedule for this team
64          */
65         public Team(String name, int numWins, int strength) {
66                 this.name = name;
67                 this.numWins = numWins;
68                 this.strength = strength;
69         }
70         
71         /** 
72          * returns true if two teams are identical
73          * 
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.
77          */
78         public boolean equals(Object other) {
79                 boolean ret = false;
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) {
84                                                 ret = true;
85                                         }
86                                 }
87                         }
88                 }
89                 return ret;
90         }
91         
92         /**
93          * compareTo provided to allow sorting of Team objects
94          * 
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.
105          */
106         public int compareTo(Team other) {
107                 int ret = 0;
108                 if (this.numWins < other.numWins) {
109                         ret = 1;
110                 } else if (this.numWins > other.numWins) {
111                         ret = -1;
112                 } else {
113                         if (this.strength < other.strength) {
114                                 ret = 1;
115                         } else if (this.strength > other.strength) {
116                                 ret = -1;
117                         } else {
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] ) {
122                                                 ret = 1;
123                                                 break;
124                                         } else if ( thisName[i] > otherName[i] ) {
125                                                 ret = -1;
126                                                 break;
127                                         }
128                                 }
129                         }
130                 }
131                 return ret;
132         }
133         
134         /**
135          * accessor method for team name 
136          * 
137          * @@return returns team name
138          */
139         public String getTeamName() {
140                 return this.name;
141         }
142         
143         /**
144          * accessor method for number of wins for this team 
145          * 
146          * @@return returns the number of wins
147          */
148         public int getWins() {
149                 return this.numWins;
150         }
151         
152         /**
153          * accessor method for the strength of schedule for this team 
154          * 
155          * @@return returns the strength of schedule
156          */
157         public int getStrengthOfSchedule() {
158                 return this.strength;
159         }
160         
161         /**
162          * a simple implementation of 'toString()'
163          * 
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."
167          */
168         public String toString() {
169                 return "team: " + this.name + " has: " + this.numWins + " wins " +
170                                 "under a schedule whose strength was rated: " + this.strength +
171                                 " out of 10";
172         }
179 @Initial revision
181 text
182 @d5 1
183 a5 1
184  *     $Id$
185 d8 4
186 a11 1
187  *     $Log$
188 d84 1
189 a84 1
190                         if (this.strength < other.numWins) {
191 d86 1
192 a86 1
193                         } else if (this.strength > other.numWins) {