first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

170
CS1322/p2/Gator.java Normal file
View File

@@ -0,0 +1,170 @@
/**
* <PRE>
* Gator.java
*
* Revisions: 1.0 Sep. 18, 2002
* Created the Gator class
* 1.1 Sep. 18, 2002
* Finished the Gator Class
* 1.1f Sep. 18, 2002
* Cleaned up equals() to make 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 Gator extends Animal implements SwimmingType{
/**
*depth of the gator
*/
private int depth;
////////////////
//Constructors//
////////////////
/**
*Gator Constructor
*@param name the name of the gator
*sets depth to 0
*/
public Gator(String name){
super(name);
this.depth = 0;
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*set the depth of the gator
*@param depth the value to be applied
*/
public void setDepth(int depth){
if(depth > 50){
this.depth = 50;
}
else {
this.depth = depth;
}
}
/**
*get the depth of the gator
*@return the depth of the gator
*/
public int getDepth(){
return this.depth;
}
///////////
//Methods//
///////////
/**
*Give the dangerous value of the Gator
*@return true, the gator is dangerous
*/
public boolean isDangerous(){
return true;
}
/**
*Have the Gator eat some food
*acceptible foods: chicken,beef,pork,human,mystery meat
*@param if the food is of the above name, set isHungry to false
*/
public void eat(String food){
if(food.equals("chicken")){
setIsHungry(false);
}
else if(food.equals("beef")){
setIsHungry(false);
}
else if(food.equals("pork")){
setIsHungry(false);
}
else if(food.equals("human")){
setIsHungry(false);
}
else if(food.equals("mystery meat")){
setIsHungry(false);
}
}//end of eat(food)
/**
*Find the equality of Gator
*@param obj the Object to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof Gator)){
return false;
}
if(!super.equals(obj)){
return false;
}
Gator temp = (Gator)obj;
if(temp.getDepth() != this.getDepth()){
return false;
}
return true;
}//end of equals(Object)
/**
* Change standard string to output to be used for this specific program
*
* <br><br>
* @return phrase as string
*/
public String toString()
{
return ("A Gator named " + getName() + " at depth " + getDepth() +
" which is " + ((this.getIsHungry())?"hungry." : "not hungry."));
}
/********************************************/
/**
* Debugging main for class Gator.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Gator gator = new Gator("bob");
gator.setIsHungry(true);
System.out.println(gator);
gator.eat("chicken");
System.out.println(gator);
gator.setDepth(100);
System.out.println(gator);
System.out.println(gator.isDangerous());
Gator gator2 = new Gator("Steve");
System.out.println(gator.equals(gator));
System.out.println(gator.equals(gator2));
String bob = "bob";
System.out.println(gator.equals(bob));
}// end of main(String[] args)
}// end of class Gator