first commit
This commit is contained in:
125
CS1322/p2/ZooBuilding.java
Normal file
125
CS1322/p2/ZooBuilding.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* ZooBuilding.java
|
||||
*
|
||||
* Revisions: 1.0 Sep. 26, 2002
|
||||
* Created the ZooBuilding 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 abstract class ZooBuilding {
|
||||
|
||||
/**
|
||||
*theAnimals list meant for storing
|
||||
*the animals of the building
|
||||
*/
|
||||
private LinkedList theAnimals;
|
||||
|
||||
/**
|
||||
*holds the name of the building
|
||||
*/
|
||||
private String name;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/*
|
||||
*Constructor for ZooBuilding
|
||||
*@param name, the name of the zoobuilding
|
||||
*/
|
||||
public ZooBuilding(String name){
|
||||
this.name = name;
|
||||
theAnimals = new LinkedList();
|
||||
}
|
||||
|
||||
/////////////
|
||||
//Accessors//
|
||||
/////////////
|
||||
|
||||
/**
|
||||
*@return the List of Animals
|
||||
*/
|
||||
public LinkedList getTheAnimals(){
|
||||
return theAnimals;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return the value of name
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*@return number of Animals in the Zoo
|
||||
*/
|
||||
public int getHungryAnimals(){
|
||||
int total=0;
|
||||
Animal aTemp;
|
||||
for(int i=0; i<theAnimals.size(); i++){
|
||||
aTemp = (Animal)theAnimals.removeFromBack();
|
||||
if(aTemp.getIsHungry() == true){
|
||||
total++;
|
||||
}
|
||||
theAnimals.addToFront(aTemp);
|
||||
}
|
||||
return total;
|
||||
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*Check if its safe to enter
|
||||
*@return yes/no
|
||||
*/
|
||||
public abstract boolean isSafeToEnter();
|
||||
|
||||
/**
|
||||
*Feed the Animals param food
|
||||
*@param food, the food to feed all the animals
|
||||
*/
|
||||
public void feedAnimals(String food){
|
||||
//why feed them if there is a sign clearly saying not to?
|
||||
if(!(isSafeToEnter())){
|
||||
System.out.println("The building is unsafe to enter!");
|
||||
return;
|
||||
}
|
||||
Animal aTemp;
|
||||
for(int i=0; i<theAnimals.size(); i++){
|
||||
aTemp = (Animal)theAnimals.removeFromBack();
|
||||
aTemp.eat(food);
|
||||
theAnimals.addToFront(aTemp);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************/
|
||||
|
||||
/**
|
||||
* Debugging main for class ZooBuilding.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class ZooBuilding
|
||||
Reference in New Issue
Block a user