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

143 lines
3.5 KiB
Java

/**
* <PRE>
* Aviary.java
*
* Revisions: 1.0 Sep. 26, 2002
* Created the Aviary class
* 1.1 Sep. 28, 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. 28, 2002
*/
public class Aviary extends ZooBuilding{
/**
*whether or not the net is closed
*/
boolean netClosed;
////////////////
//Constructors//
////////////////
/**
*Constructor for Aviary
*@param name the name of the Aviary
*/
public Aviary(String name){
super(name);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*@return value of netClosed
*/
public boolean getNetClosed(){
return netClosed;
}
/**
*@param netClosed, the new value of netClosed
*/
public void setNetClosed(boolean netClosed){
this.netClosed = netClosed;
}
/////////////
//.Methods.//
/////////////
/**
*@return the value of netClosed
*/
public boolean isSafeToEnter(){
Animal aTemp;
FlyingType fTemp;
boolean bSafe = true;
for(int i=0; i<getTheAnimals().size(); i++){
aTemp = (Animal)getTheAnimals().removeFromBack();
fTemp = (FlyingType)aTemp;
if(aTemp.isDangerous() && fTemp.getAltitude() < 75){
bSafe = false;
}
getTheAnimals().addToFront(aTemp);
}
if(!getNetClosed()){
bSafe = false;
}
return bSafe;
}
/**
*override default toString for use with this program
*/
public String toString(){
return ("An Aviary named " + getName() + ".");
}
/***********************************************************/
/**
* Debugging main for class Aviary.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Aviary dancedance = new Aviary("Stinky");
dancedance.getTheAnimals().addToBack(new Duck("Bob"));
dancedance.getTheAnimals().addToFront(new Bat("Ronald"));
dancedance.getTheAnimals().addToFront(new Bat("McDonald"));
dancedance.getTheAnimals().listOut();
System.out.println();
dancedance.setNetClosed(true);
System.out.println(dancedance.getHungryAnimals());
System.out.println();
dancedance.getTheAnimals().listOut();
Animal temp = (Animal)dancedance.getTheAnimals().getFirst();
temp.setIsHungry(true);
System.out.println();
dancedance.getTheAnimals().listOut();
System.out.println();
dancedance.setNetClosed(true);
System.out.println(dancedance.getHungryAnimals());
System.out.println();
dancedance.getTheAnimals().listOut();
System.out.println();
dancedance.getTheAnimals().listOut();
System.out.println();
dancedance.setNetClosed(false);
dancedance.feedAnimals("insects");
dancedance.setNetClosed(true);
dancedance.feedAnimals("insects");
System.out.println();
dancedance.getTheAnimals().listOut();
System.out.println();
System.out.println(dancedance);
}// end of main(String[] args)
}// end of class Aviary