146 lines
3.0 KiB
Java
146 lines
3.0 KiB
Java
/**
|
|
* <PRE>
|
|
* Bat.java
|
|
*
|
|
* Revisions: 1.0 Sep. 19, 2002
|
|
* Created the Bat class
|
|
*
|
|
* </PRE>
|
|
*
|
|
* 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 <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
|
* @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.
|
|
*
|
|
* <br><br>
|
|
* @param args a String array of command line arguments.
|
|
*/
|
|
public static void main(String[] args) {
|
|
Bat bat = new Bat("Batty");
|
|
|
|
//bats can live underground
|
|
bat.setAltitude(-10);
|
|
|
|
System.out.println(bat);
|
|
|
|
Bat bat2 = new Bat("Pooty");
|
|
|
|
bat2.setAltitude(10);
|
|
bat2.setIsHungry(true);
|
|
|
|
System.out.println(bat2);
|
|
|
|
System.out.println(bat.equals(bat2));
|
|
System.out.println(bat.equals(bat));
|
|
|
|
}// end of main(String[] args)
|
|
|
|
}// end of class Bat
|