first commit
This commit is contained in:
128
CS1322/final/Animals/Animal.java
Normal file
128
CS1322/final/Animals/Animal.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* Animal.java
|
||||
*
|
||||
* Revisions: 1.0 Sep. 17, 2002
|
||||
* Created the Animal class
|
||||
* 1.1 Sep. 17, 2002
|
||||
* Finished the Animal 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.1, Sep. 17, 2002
|
||||
*/
|
||||
|
||||
public abstract class Animal {
|
||||
|
||||
/**
|
||||
*whether or not the animal is hungry
|
||||
*/
|
||||
private boolean isHungry;
|
||||
|
||||
/**
|
||||
*holds the animal's name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*Constructor for Animal
|
||||
*@param name the value to assign name
|
||||
*/
|
||||
public Animal(String name){
|
||||
this.name = name;
|
||||
isHungry = false;
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
//Accessors/Modifiers//
|
||||
///////////////////////
|
||||
|
||||
/**
|
||||
*isHungry Modifier
|
||||
*@param h the value applied to isHungry
|
||||
*/
|
||||
public void setIsHungry(boolean h){
|
||||
isHungry = h;
|
||||
}
|
||||
|
||||
/**
|
||||
*isHungry Accessor
|
||||
*@return the value of isHungry
|
||||
*/
|
||||
public boolean getIsHungry(){
|
||||
return isHungry;
|
||||
}
|
||||
|
||||
/**
|
||||
*Accessor for name
|
||||
*@return the value of name
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*@return whether the animal is dangerous or not
|
||||
*/
|
||||
public abstract boolean isDangerous();
|
||||
|
||||
/**
|
||||
*Give the animal something to eat
|
||||
*@param food, the food to feed the animal
|
||||
*/
|
||||
public abstract void eat(String food);
|
||||
|
||||
/**
|
||||
*Equals method
|
||||
*@param the value to test equality with
|
||||
*@return the truthnes of the equality
|
||||
*/
|
||||
public boolean equals(Object obj){
|
||||
|
||||
if((obj instanceof Animal) == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
Animal temp = (Animal)obj;
|
||||
//added "this." to make it verbose and more readable
|
||||
if(!(temp.getName().equals(this.getName()))){
|
||||
return false;
|
||||
}
|
||||
if(temp.isDangerous() != this.isDangerous()){
|
||||
return false;
|
||||
}
|
||||
if(temp.getIsHungry() != this.getIsHungry()){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class Animal.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//nuttin ta test
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class Animal
|
||||
Reference in New Issue
Block a user