All pastes #332664 Raw Edit

Stuff

public java v1 · immutable
#332664 ·published 2007-01-30 04:58 UTC
rendered paste body
/* * Player.java * * Version: *      $Id$ * * Revisions: *      $Log$ * *//** * This class represents a baseball player in Major League Baseball.  * For each player, we record the year the player won the home run champion  * title, the name and team of the player, and the number of home runs the  * player hit during the season. * * @author      SOME COOL DUDE */public class Player implements Comparable<Player> {        private String winYear;    private String playerName;    private String playerTeam;    private int hr;    /**     * The default constructor     *     * @param winyear Year player won hr title     * @param playerName Name of player     * @param playerTeam Name of team     * @param hr Number of player hit during season     */    public Player(String winYear, String playerName,                   String playerTeam, int hr){                this.winyear = winyear;        this.playerName = playerName;        this.playerTeam = playerTeam;        this.hr = hr;    }        /**     * Compares two players primarily for sorting.     *     * @param other     * @return     */     public int compareTo(Player other){        if (playerName < other.getName()){            return -1;        } else if (playerName > other.getName()){            return 1;        } else if (playerName == other.getName()){            if (playerTeam < other.){                return -2;            } else if (playerTeam == other.playerTeam){                return 0;            } else if (playerTeam > other.playerTeam){                return 2;            }        }     }    /**     * Compare this player to the specified player.     *     * @param other     * @return     */     public boolean equals(Object other){        return (compareTo(other) == 0);     }     /**      * Get the number of home runs.      *      */      public int getHR(){          return hr;      }    /**     * Get the name of this player.     *     */     public String getName(){         return playerName;     }    /**     * Get the name of this Team.     *     */     public String getTeam(){         return playerTeam;     }    /**     * Get the hash code of this object.     *     */     public int hashCode(){         return playerName.hashCode() + playerTeam.hashCode();     }    /**     * Print the name, the team, the number of home runs, and the year of     * this player.     *     */     public String toString(){         private String string;         string = playerTeam + "'s " + playerName + " hit " + hr +                             "home runs in " playerYear;         return string;     }