import java.util.ArrayList; /* *This is the class with all of the information about a team that *played in the NCAA basketball tournament */ public class TeamInfo { private String team; private int wins; private int losses; private ArrayList years; /** *@param name is the team name */ public TeamInfo(String name) { team = name; years = new ArrayList(); wins = 0; losses = 0; } // end constructor /** *This adds a year the a team's year list *@param aYear is the year that is added if it is not in the year list */ public void addYear(String aYear) { if( !years.contains(aYear) ) { years.add(aYear); } // end if } // end addYear /** *@return the name of the team */ public String getTeam() { return team; } // end getTeam /** * TeamInfo objects are equal if the team names are equal * @return true if names are equal; false otherwise */ public boolean equals(Object x) { if( !( x instanceof TeamInfo ) ) return false; return getTeam().equals(((TeamInfo)x).getTeam()); } // end equals /** * Returns an int value asociated with this object * @returns a hash code value for the object. **/ public int hashCode() { return getTeam().hashCode(); } // end hashCode /** * Mofifies the number of wins by adding one. * Add one to the wins */ public void incrementWins() { wins++; } // end incrementWins /** * Mofifies the number of losses by adding one. * Add one to the losses */ public void incrementLosses() { losses++; } // end IncrementLosses /** *@return the name, wins, losses and each year of participation in *the tournament as a String */ public String toString() { String out = team + " had " + getWins() + " win" + ((getWins() != 1)?"s":"") + " and " + getLosses() + " loss" + ((getLosses() != 1)?"es":"") + "\n"; out += "They played in the following years:\n"; for( int i = 0; i < getYears().size() ; i++ ) { out += years.get(i) + ", "; if( (i+1)%10 == 0 ) out += "\n"; } // end for int lastComma = out.lastIndexOf(", "); return out.substring(0,lastComma) + "\n\n"; } // end toString() /** * Accessor for the wins *@return the number of wins */ public int getWins() { return wins; } // end getWins /** * Accessor for the losses *@return the number of losses */ public int getLosses() { return losses; } // end getLosses /** * Accessor for the years *@return the ArrayList of years */ public ArrayList getYears() { return years; } // end getYears } // end TeamInfo