Files
GTSchoolShit/CS1322/p2/Shark.java
2025-06-07 01:59:34 -04:00

115 lines
2.6 KiB
Java

/**
* <PRE>
* Shark.java
*
* Revisions: 1.0 Sep. 19, 2002
* Created the Shark class
* 1.1 Sep. 20, 2002
* Finished, Compiled, Commented
*
* </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. 20, 2002
*/
public class Shark extends Fish{
////////////////
//Constructors//
////////////////
/**
*Constructor for Shark
*@param name of the Shark
*@param depth of the shark
*/
public Shark(String name, int depth){
super(name,depth);
}
///////////
//Methods//
///////////
/**
*Eat method for Shark
*@param food to eat, if it's human, chicken,fish isHungry = false
*/
public void eat(String food)
{
if(food.equals("human")){ //mmmmmm...
setIsHungry(false);
}
else if(food.equals("chicken")){ //tastes like chicken
setIsHungry(false);
}
else if(food.equals("fish")){ //IT ATE ITS OWN SUPERCLASS!!!
setIsHungry(false);
}
}
/**
*Give the dangerous value of the Shark
*@return true, the Shark is dangerous
*/
public boolean isDangerous(){
return true;
}
/**
*Find the equality of Shark
*@param obj the Object to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof Shark)){
return false;
}
if(!(super.equals(obj))){
return false;
}
return true;
}
/**
*Modify String for this particular program
*@return the data of the Shark as a string statement
*/
public String toString(){
return ("A Shark named " + getName() + " at depth " + getDepth() +
" that is " + (getIsHungry()?"":"not ") + "hungry.");
}
/**
* Debugging main for class Shark.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Shark shark = new Shark("Sharky",150);
shark.setIsHungry(true);
shark.setDepth(151);
System.out.println(shark);
Shark shark2 = new Shark("Pissey",-52);
System.out.println(shark2);
System.out.println(shark.equals(shark2));
System.out.println(shark.equals(shark));
}// end of main(String[] args)
}// end of class Shark