first commit
This commit is contained in:
179
CS1322/final/Animals/Bird.java
Normal file
179
CS1322/final/Animals/Bird.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Bird.java
|
||||
*
|
||||
* Revisions: 1.0 Sep. 18, 2002
|
||||
* Created the Bird class
|
||||
* 1.1 Sep. 18, 2002
|
||||
* Finished the Bird class
|
||||
* 1.1f Sep. 18,2002
|
||||
* Cleaned equals() to make it more readable
|
||||
*
|
||||
* </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.1f, Sep. 18, 2002
|
||||
*/
|
||||
|
||||
|
||||
public class Bird extends Animal implements FlyingType{
|
||||
|
||||
/**
|
||||
*whether or not the bird is dangerous
|
||||
*/
|
||||
private boolean dangerous;
|
||||
|
||||
/**
|
||||
*species of the bird
|
||||
*/
|
||||
private String species;
|
||||
|
||||
/**
|
||||
*altitude of the bird
|
||||
*/
|
||||
private int altitude;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*@param name the value to give to name
|
||||
*@param species the value to give species
|
||||
*@param dangerous the value to give dangerous
|
||||
*@param alt the value to give altitude
|
||||
*/
|
||||
public Bird(String name, String species,
|
||||
boolean dangerous, int alt){
|
||||
super(name);
|
||||
//left "this." for alt just for consistency
|
||||
this.dangerous = dangerous;
|
||||
this.species = species;
|
||||
this.altitude = alt;
|
||||
}
|
||||
|
||||
/**
|
||||
*@param name the value to give to name
|
||||
*@param species the value to give species
|
||||
*@param dangerous the value to give dangerous
|
||||
*Altitude will be set to 0
|
||||
*/
|
||||
public Bird(String name, String species, boolean dangerous){
|
||||
this(name,species,dangerous,0);
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
//Accessors/Modifiers//
|
||||
///////////////////////
|
||||
|
||||
/**
|
||||
*Accessor for species
|
||||
*@return the value of species
|
||||
*/
|
||||
public String getSpecies(){
|
||||
return species;
|
||||
}
|
||||
|
||||
/**
|
||||
*Accessor for altitude
|
||||
*@return the altitude
|
||||
*/
|
||||
public int getAltitude(){
|
||||
return altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*Modifier for altitude
|
||||
*@param the value to be assigned to altitude
|
||||
*/
|
||||
public void setAltitude(int altitude){
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return the danger of the bird
|
||||
*/
|
||||
public boolean isDangerous(){
|
||||
return dangerous;
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*Modify String for this particular program
|
||||
*@return the data of the Bird as a string statement
|
||||
*/
|
||||
public String toString(){
|
||||
return ("A " + getSpecies() + " named " + getName() + " at altitude " +
|
||||
getAltitude() + " that is " + (isDangerous()?"":"not ") + "dangerous" +
|
||||
" and is " + (getIsHungry()?"":"not ") + "hungry.");
|
||||
}
|
||||
|
||||
/**
|
||||
*Eat method for Bird
|
||||
*@param food to eat, if it's bird seed isHungry = false
|
||||
*/
|
||||
public void eat(String food)
|
||||
{
|
||||
if(food.equals("bird seed")){
|
||||
setIsHungry(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*equals method for Bird
|
||||
*@param obj the value to be tested
|
||||
*@return equality true/false
|
||||
*/
|
||||
public boolean equals(Object obj){
|
||||
|
||||
if(!(obj instanceof Bird)){
|
||||
return false;
|
||||
}
|
||||
if(!super.equals(obj)){
|
||||
return false;
|
||||
}
|
||||
|
||||
Bird bTemp = (Bird)obj;
|
||||
//use of "this." to make it explicit
|
||||
if(bTemp.getSpecies() != this.getSpecies()){
|
||||
return false;
|
||||
}
|
||||
if(bTemp.getAltitude() != this.getAltitude()){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* Debugging main for class Bird.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Bird bird = new Bird("Tweety","Canary",true,26);
|
||||
System.out.println(bird);
|
||||
|
||||
Bird bird2 = new Bird("Bob","Eagle",false);
|
||||
bird2.setIsHungry(true);
|
||||
System.out.println(bird2);
|
||||
System.out.println(bird.equals(bird2));
|
||||
System.out.println(bird.equals(bird));
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class Bird
|
||||
Reference in New Issue
Block a user