/** *
* Bat.java * * Revisions: 1.0 Sep. 19, 2002 * Created the Bat class * ** * Collaboration Statement: * I worked on the homework assignment alone, using only * course materials. * * Created with JCreatorLE, some indents are off when viewed through notepad * or EMACS * * @author Jose Manuel Caban * @version Version 1.0, Sep. 19, 2002 */ public class Bat extends Animal implements FlyingType{ /** *altitude of the Bat */ private int altitude; //////////////// //Constructors// //////////////// /** *Constructor for Bat *@param name, the name of the bat */ public Bat(String name){ super(name); } /////////////////////// //Accessors/Modifiers// /////////////////////// /** *Modifier for altitude *@param altitude, the value to be applied to altitude */ public void setAltitude(int altitude){ this.altitude = altitude; } /** *Accessor for altitude *@return the value of altitude */ public int getAltitude(){ return altitude; } /////////// //Methods// /////////// /** *Give the dangerous value of the Bat *@return false, the Bat is not dangerous */ public boolean isDangerous(){ return false; } /** *Eat method for Bat *@param food to eat, if it's "insects" isHungry = false */ public void eat(String food) { if(food.equals("insects")){ setIsHungry(false); } } /** *Find the equality of Bat *@param obj the Object to be compared to *@return the equality value */ public boolean equals(Object obj){ if(!(obj instanceof Bat)){ return false; } Bat temp = (Bat)obj; //added "this." to make explicit, God why do I type this for every //single animal class? if(temp.getAltitude() != this.getAltitude()){ return false; } if(!(super.equals(obj))){ return false; } return true; } /** *Modify String for this particular program *@return the data of the Bat as a string statement */ public String toString(){ return ("A Bat named " + getName() + " at altitude " + getAltitude() + " that is " + (getIsHungry() ?"":"not ") + "hungry."); } /** * Debugging main for class Bat. * This method will rigorously test my code. * *