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

2
CS1322/final/Animal.java Normal file
View File

@@ -0,0 +1,2 @@
public class Animal{
}

View 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

View File

@@ -0,0 +1,99 @@
/**
* <PRE>
* Aquarium.java
*
* Revisions: 1.0 Sep. 26, 2002
* Created the Aquarium 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 Aquarium extends ZooBuilding{
////////////////
//Constructors//
////////////////
/**
*Constructor for Aquarium
*@param name the name for the Aquarium
*/
public Aquarium(String name){
super(name);
}
///////////
//Methods//
///////////
/**
*@return true if it is safe to enter
*Safe if all dangerous animals are 30 feet underwater
*/
public boolean isSafeToEnter(){
Animal aTemp;
SwimmingType sTemp;
boolean bSafe = true;
for(int i=0; i<getTheAnimals().size(); i++){
aTemp = (Animal)getTheAnimals().removeFromBack();
sTemp = (SwimmingType)aTemp;
if(aTemp.isDangerous() && sTemp.getDepth() < 30){
bSafe = false;
}
getTheAnimals().addToFront(aTemp);
}
return bSafe;
}
/**
*override default string method for use with this program
*/
public String toString(){
return ("An Aquarium named " + getName() + ".");
}
/****************************************************/
/**
* Debugging main for class Aquarium.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Aquarium swimswim = new Aquarium("Smells like Fish");
swimswim.getTheAnimals().addToFront(new Duck("Bob"));
swimswim.getTheAnimals().addToBack(new Gator("Crocodile"));
swimswim.getTheAnimals().addToFront(new GoldFish("Can't Remember Jack",5));
swimswim.getTheAnimals().listOut();
System.out.println();
Gator Tom = (Gator)swimswim.getTheAnimals().getLast();
Tom.setDepth(50);
System.out.println(swimswim.isSafeToEnter());
Tom.setDepth(4);
System.out.println(swimswim.isSafeToEnter());
swimswim.getTheAnimals().listOut();
System.out.println(swimswim);
}// end of main(String[] args)
}// end of class Aquarium

View File

@@ -0,0 +1,142 @@
/**
* <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

View File

@@ -0,0 +1,145 @@
/**
* <PRE>
* Bat.java
*
* Revisions: 1.0 Sep. 19, 2002
* Created the Bat 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.0, Sep. 19, 2002
*/
public class Bat extends Animal implements FlyingType{
/**
*altitude of the Bat
*/
private int altitude;
////////////////
//Constructors//
////////////////
/**
*Constructor for Bat
*@param name, the name of the bat
*/
public Bat(String name){
super(name);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Modifier for altitude
*@param altitude, the value to be applied to altitude
*/
public void setAltitude(int altitude){
this.altitude = altitude;
}
/**
*Accessor for altitude
*@return the value of altitude
*/
public int getAltitude(){
return altitude;
}
///////////
//Methods//
///////////
/**
*Give the dangerous value of the Bat
*@return false, the Bat is not dangerous
*/
public boolean isDangerous(){
return false;
}
/**
*Eat method for Bat
*@param food to eat, if it's "insects" isHungry = false
*/
public void eat(String food)
{
if(food.equals("insects")){
setIsHungry(false);
}
}
/**
*Find the equality of Bat
*@param obj the Object to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof Bat)){
return false;
}
Bat temp = (Bat)obj;
//added "this." to make explicit, God why do I type this for every
//single animal class?
if(temp.getAltitude() != this.getAltitude()){
return false;
}
if(!(super.equals(obj))){
return false;
}
return true;
}
/**
*Modify String for this particular program
*@return the data of the Bat as a string statement
*/
public String toString(){
return ("A Bat named " + getName() + " at altitude " + getAltitude() +
" that is " + (getIsHungry() ?"":"not ") + "hungry.");
}
/**
* Debugging main for class Bat.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Bat bat = new Bat("Batty");
//bats can live underground
bat.setAltitude(-10);
System.out.println(bat);
Bat bat2 = new Bat("Pooty");
bat2.setAltitude(10);
bat2.setIsHungry(true);
System.out.println(bat2);
System.out.println(bat.equals(bat2));
System.out.println(bat.equals(bat));
}// end of main(String[] args)
}// end of class Bat

View File

@@ -0,0 +1,179 @@
/**
* <PRE>
* Bird.java
*
* Revisions: 1.0 Sep. 18, 2002
* Created the Bird class
* 1.1 Sep. 18, 2002
* Finished the Bird class
* 1.1f Sep. 18,2002
* Cleaned equals() to make it 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 Bird extends Animal implements FlyingType{
/**
*whether or not the bird is dangerous
*/
private boolean dangerous;
/**
*species of the bird
*/
private String species;
/**
*altitude of the bird
*/
private int altitude;
////////////////
//Constructors//
////////////////
/**
*@param name the value to give to name
*@param species the value to give species
*@param dangerous the value to give dangerous
*@param alt the value to give altitude
*/
public Bird(String name, String species,
boolean dangerous, int alt){
super(name);
//left "this." for alt just for consistency
this.dangerous = dangerous;
this.species = species;
this.altitude = alt;
}
/**
*@param name the value to give to name
*@param species the value to give species
*@param dangerous the value to give dangerous
*Altitude will be set to 0
*/
public Bird(String name, String species, boolean dangerous){
this(name,species,dangerous,0);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Accessor for species
*@return the value of species
*/
public String getSpecies(){
return species;
}
/**
*Accessor for altitude
*@return the altitude
*/
public int getAltitude(){
return altitude;
}
/**
*Modifier for altitude
*@param the value to be assigned to altitude
*/
public void setAltitude(int altitude){
this.altitude = altitude;
}
/**
*@return the danger of the bird
*/
public boolean isDangerous(){
return dangerous;
}
///////////
//Methods//
///////////
/**
*Modify String for this particular program
*@return the data of the Bird as a string statement
*/
public String toString(){
return ("A " + getSpecies() + " named " + getName() + " at altitude " +
getAltitude() + " that is " + (isDangerous()?"":"not ") + "dangerous" +
" and is " + (getIsHungry()?"":"not ") + "hungry.");
}
/**
*Eat method for Bird
*@param food to eat, if it's bird seed isHungry = false
*/
public void eat(String food)
{
if(food.equals("bird seed")){
setIsHungry(false);
}
}
/**
*equals method for Bird
*@param obj the value to be tested
*@return equality true/false
*/
public boolean equals(Object obj){
if(!(obj instanceof Bird)){
return false;
}
if(!super.equals(obj)){
return false;
}
Bird bTemp = (Bird)obj;
//use of "this." to make it explicit
if(bTemp.getSpecies() != this.getSpecies()){
return false;
}
if(bTemp.getAltitude() != this.getAltitude()){
return false;
}
return true;
}
/********************************************************/
/**
* Debugging main for class Bird.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Bird bird = new Bird("Tweety","Canary",true,26);
System.out.println(bird);
Bird bird2 = new Bird("Bob","Eagle",false);
bird2.setIsHungry(true);
System.out.println(bird2);
System.out.println(bird.equals(bird2));
System.out.println(bird.equals(bird));
}// end of main(String[] args)
}// end of class Bird

View File

@@ -0,0 +1,149 @@
/**
* <PRE>
* Duck.java
*
* Revisions: 1.0 Sep. 19, 2002
* Created the Duck class
* 1.1 Sep. 21, 2002
* Compiled, Finished, 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. 21, 2002
*/
public class Duck extends Bird implements SwimmingType{
/**
*depth of Duck
*/
private int depth;
/**
*whether or not the Duck is in flight
*/
private boolean flying;
////////////////
//Constructors//
////////////////
/**
*Constructor for Duck
*@param name the name of the duck
*/
public Duck(String name){
super(name,"Duck",false);
setDepth(0);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Modifier for depth
*@param the new value for depth
*/
public void setDepth(int depth){
this.depth = depth;
flying = false;
}
/**
*Accessor for depth
*@return the value of depth
*/
public int getDepth(){
return depth;
}
/**
*Accessor for flying
*@return value of flying
*/
public boolean isFlying(){
return flying;
}
/**
*Set the altitude of the Duck and flying to true
*@param altitude the height of the duck
*/
public void setAltitude(int altitude){
super.setAltitude(altitude);
flying = true;
}
///////////
//Methods//
///////////
/**
*Find the equality of Duck
*@param obj the Object to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof Bird)){
return false;
}
Duck dTemp = (Duck)obj;
if(dTemp.getDepth() != this.getDepth()){
return false;
}
if(dTemp.isFlying() != this.isFlying()){
return false;
}
if(!(super.equals(obj))){
return false;
}
return true;
}
/**
* Change standard string to output to be used for this specific program
* @return phrase as string
*/
public String toString(){
if(isFlying()){
return super.toString();
}
else{ //!isFlying()
return ("A swimming duck named " + getName() + " at depth " +
getDepth() + " that is " + (getIsHungry()?"":"not ") +
"hungry.");
}
}
/*****************************************************/
/**
* Debugging main for class Duck.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Duck duck = new Duck("Daffy");
System.out.println(duck);
duck.setAltitude(8);
duck.setIsHungry(true);
System.out.println(duck);
System.out.println(duck.equals(duck));
System.out.println(duck.equals("bob"));
}// end of main(String[] args)
}// end of class Duck

View File

@@ -0,0 +1,108 @@
/**
* <PRE>
* Fish.java
*
* Revisions: 1.0 Sep. 18, 2002
* Created the Fish class
* 1.1 Sep. 18, 2002
* Finished the Fish 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 abstract class Fish extends Animal implements SwimmingType{
/**
*depth of Fish
*/
private int depth;
////////////////
//Constructors//
////////////////
/**
*Constructor for Fish
*@param name, the name of the fish
*@param depth, the depth of the fish
*/
public Fish(String name, int depth){
super(name);
this.setDepth(depth);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Set the depth of Fish
*@param depth the value to be applied
*/
public void setDepth(int depth){
if(depth < 0){
this.depth = 0;
}
else{
this.depth = depth;
}
}
/**
*Return the depth of the Fish
*@return the value of depth
*/
public int getDepth(){
return depth;
}
///////////
//Methods//
///////////
/**
*Find the equality of Fish
*@param obj the Object to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof Fish)){
return false;
}
if(!super.equals(obj)){
return false;
}
Fish fTemp = (Fish)obj;
//use of "this." is to make it explicit
if(fTemp.getDepth() != this.getDepth()){
return false;
}
return true;
}
/**
* Debugging main for class Fish.
* 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 Fish

View File

@@ -0,0 +1,36 @@
/**
* <PRE>
* FlyingType.java
*
* Revisions: 1.0 Sep. 21, 2002
* Created the FlyingType interface
* 1.1 Sep. 29, 2002
* 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. 29, 2002
*/
public interface FlyingType {
/**
*set altitude of Animal
*@param altitude, the altitude of the animal
*/
public void setAltitude(int alt);
/**
*@return altitude of the animal
*/
public int getAltitude();
}// end of class FlyingType

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

View File

@@ -0,0 +1,106 @@
/**
* <PRE>
* GoldFish.java
*
* Revisions: 1.0 Sep. 19, 2002
* Created the GoldFish 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 GoldFish extends Fish{
////////////////
//Constructors//
////////////////
/**
*Constructor for GoldFish
*@param name to be given to goldfish
*@param value to be given to depth
*/
public GoldFish(String name, int depth){
super(name,depth);
}
///////////
//Methods//
///////////
/**
*isDangerous method for fish
*@return false
*/
public boolean isDangerous(){
return false; //you TA's obviously don't know the goldfish like i do...
}
/**
*Have the Goldfish eat some food
*@param if the food is "fish food", set isHungry to false
*/
public void eat(String food){
if(food.equals("fish food")){
setIsHungry(false);
}
}
/**
* Change standard string to output to be used for this specific program
* @return phrase as string
*/
public String toString(){
return ("A GoldFish named " + getName() + " at depth " + getDepth() +
" that is " + (getIsHungry()?"":"not ") + "hungry.");
}
/**
*Equals method for GoldFish
*@param obj the value to be compared to
*@return false if not a GoldFish
*/
public boolean equals(Object obj){
if(!(obj instanceof GoldFish)){
return false;
}
if(!(super.equals(obj))){
return false;
}
return true;
}
/**
* Debugging main for class GoldFish.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
GoldFish butch = new GoldFish("Butch", -6); //I've seen em leave their cup
System.out.println(butch);
GoldFish butch2 = new GoldFish("Cassidy",54);
butch2.setIsHungry(true);
System.out.println(butch2);
System.out.println(butch.equals(butch2));
System.out.println(butch.equals(butch));
}// end of main(String[] args)
}// end of class GoldFish

View File

@@ -0,0 +1,98 @@
/*====================================================================*/
/* D O N O T E D I T T H I S F I L E */
/*====================================================================*/
import java.io.*;
/**
* CS1312: IOHelper
* <PRE>
* IOHelper - a utility for reading input from the keyboard
*
* Revisions: 3.0 January 19, 2000
* Re-created class IOHelper
* Completetly Trashed old versions
* Removed backwards compatibility
*
* </PRE>
* @author <A HREF="mailto:cs1312@prism.gatech.edu">CS1312</A>
* @version Version 3.0, January 19, 2000
*/
public class IOHelper
{
/*=================================================================*/
/* C O N S T A N T S */
/*=================================================================*/
/**
* A Debug flag.
*/
public static final boolean bDEBUG = false;
/*=================================================================*/
/* C O N S T R U C T O R */
/*=================================================================*/
/**
* Declaring the default constructor private prevents anyone from
* making an instance of this class.
*/
private IOHelper()
{
System.err.println("IOHelper is not meant to be instantiated");
} // end of default constructor, IOHelper()
/*=================================================================*/
/* S T A T I C V A R I A B L E S */
/*=================================================================*/
/**
* Used by the BufferedReader to retrieve input.
* <BR><BR>
* @see #bReader bReader
*/
protected static InputStreamReader iStreamReader = new
InputStreamReader(System.in);
/**
* Retrieves input from the user using a wrapped InputStreamReader.
* <BR><BR>
* @see #iStreamReader iStreamReader
*/
protected static BufferedReader bReader = new
BufferedReader(iStreamReader);
/*=================================================================*/
/* S T A T I C M E T H O D S */
/*=================================================================*/
/**
* Retrieves input from the user using a BufferedReader
* <BR><BR>
* @return a String entered by the User
*/
public static final String readLine()
{
String strReturn = "";
try
{
strReturn = bReader.readLine();
} // end of try
catch (IOException ioe)
{
if (bDEBUG)
{
System.err.println("IOHelper: " + ioe.getMessage());
} // end of if
} // end of catch(IOException)
catch (NullPointerException npe)
{
/* This should NEVER happen */
System.err.println("IOHelper: " + npe.getMessage());
System.err.println("Please report this error to cs1312");
System.exit(1);
} // end of catch(NullPointerException)
return strReturn;
} // end of static method, readLine()
} // end of class IOHelper

View File

@@ -0,0 +1,132 @@
/**
* <PRE>
* LLNode.java
*
* Revisions: 1.0 Sep. 21, 2002
* Created the LLNode class
* 1.1 Sep. 21, 2002
* Finished 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. 21, 2002
*/
public class LLNode {
/**
*holds the node data
*/
private Object data;
/**
*holds the location of the next node
*/
private LLNode next;
//nothing to debug that this will help with,
//but its in here for good measure
private static final boolean bDebug = false;
////////////////
//Constructors//
////////////////
/**
*Defaul LLNode Constructor
*both next and data are initialized to null
*/
public LLNode(){
setNext(null);
setData(null);
}
/**
*LLNode(Object)
*next initialized to null
*@param o the value to be given to data
*/
public LLNode(Object o){
setNext(null);
setData(o);
}
/**
*LLNode(Object,LLNode)
*@param o, the value of data
*@param next, the value of next
*/
public LLNode(Object o, LLNode next){
setNext(next);
setData(o);
}
///////////////////////
//Accessors/Modifiers//
///////////////////////
/**
*Accessor for data
*@return value of data
*/
public Object getData(){
return data;
}
/**
*Modifier for data
*@param the value for data
*/
public void setData(Object data){
this.data = data;
}
/**
*Accessor for next
*@return the next node
*/
public LLNode getNext(){
return next;
}
/**
*Modifier for next
*@param the new next node
*/
public void setNext(LLNode next){
this.next = next;
}
///////////
//Methods//
///////////
public String toString(){
return (data.toString());
}
/***********************************************/
/**
* Debugging main for class LLNode.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
Integer bob = new Integer(5);
LLNode node = new LLNode(bob);
System.out.println(node);
}// end of main(String[] args)
}// end of class LLNode

View File

@@ -0,0 +1,425 @@
/**
* <PRE>
* LinkedList.java
*
* Revisions: 1.0 Sep. 21, 2002
* Created the LinkedList class
* 1.1 Sep. 26, 2002
* Compiled, Finished, 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. 26, 2002
*/
public class LinkedList {
/**
*Front of the list
*/
private LLNode head;
/**
*Back of the List
*/
private LLNode tail;
//there's actually something to debug this time!
private static final boolean bDebug = false;
////////////////
//Constructors//
////////////////
/**
*Default constructor for LinkedList
*sets head and tail to null
*/
public LinkedList(){
head = null;
tail = null;
}
///////////
//Methods//
///////////
/**
*Add node to front of list
*@param o, the data to be stored in the node
*/
public void addToFront(Object o){
LLNode node = new LLNode(o,head);
if(bDebug){System.out.print("Adding to Front:");}
head = node;
if(tail == null){
this.tail = node;
}
if(bDebug){System.out.println("Done.");}
}
/**
*Add node to back of list
*@param o, the data to be stored in the node
*/
public void addToBack(Object o){
LLNode node = new LLNode(o);
if(bDebug){System.out.print("Adding to Back:");}
if(tail != null){
tail.setNext(node);
}
tail = node;
if(head == null){
head = node;
}
if(bDebug){System.out.println("Done.");}
}
/**
*@return the data stored by the first node
*/
public Object getFirst(){
if(head != null){
return head.getData();
}
else {
return null;
}
}
/**
*@return the data stored by the last node
*/
public Object getLast(){
if(tail != null){
return tail.getData();
}
else {
return null;
}
}
/**
*@return the data stored by the first node, destroy first node
*/
public Object removeFromFront(){
if(head == null){
return null;
}
if(bDebug){System.out.print("Removing from Front:");}
Object temp = head.getData();
head = head.getNext();
if(head == null){
tail = null;
}
if(bDebug){System.out.println("Done.");}
return temp;
}
/**
*@return the data stored by the last node, destroy the last node
*/
public Object removeFromBack(){
if(tail == null){
return null;
}
if(bDebug){System.out.print("Removing from Back:");}
Object temp = tail.getData();
LLNode current = head;
if(current != tail){
//find second to last node
while(current.getNext() != tail){
current = current.getNext();
}
tail = current;
tail.setNext(null);
}
else {
tail = null;
}
if(tail == null){
head = null;
}
if(bDebug){System.out.println("Done.");}
return temp;
}
/**
*@return the number of nodes in the LinkedList
*/
public int size(){
if(head == null){
return 0;
}
if(head == tail){
return 1;
}
int count=0;
LLNode current = head;
while(current!= null){
current = current.getNext();
count++;
}
return (count);
}
/**
*Turn the LinkedList into an Array
*@return array containing all the data held by the LinkedList
*/
public Object[] asArray(){
Object[] array = new Object[this.size()];
if(head == null){
return array;
}
LLNode current = head;
int i=0;
while(current != null){
array[i] = current.getData();
i++;
current = current.getNext();
}
return array;
}
/**
*temp method to output list on screen
*meant for debugging to circumvent the array method
*/
public void listOut(){
LLNode current = head;
while(current != null){
System.out.println(current.getData());
current = current.getNext();
}
}
/**
*Find the equality of the LinkedList
*@param LL, the list to be compared to
*@return the equality value
*/
public boolean equals(Object obj){
if(!(obj instanceof LinkedList)){
return false;
}
LinkedList LL = (LinkedList)obj;
LLNode thisCurrent = this.head;
LLNode temp = LL.head;
if(this.size() != LL.size()){
return false;
}
while(thisCurrent != null){
if(!(thisCurrent.getData().equals(temp.getData()))){
return false;
}
thisCurrent = thisCurrent.getNext();
temp = temp.getNext();
}
return true;
}
/**
* Change standard string to output to be used for this specific program
* @return phrase as string
*/
public String toString(){
String ReallyLong;
ReallyLong = "[ ";
LLNode current = head;
while(current != null){
ReallyLong += current.getData().toString();
if(current.getNext() != null){
ReallyLong += ", ";
}
current = current.getNext();
}
ReallyLong += "]";
return ReallyLong;
}
/**
*Check if there is an object in the list matching o
*@return true if such an object exists
*/
public boolean contains(Object o){
LLNode current = head;
while(current != null){
if(current.getData().equals(o)){
return true;
}
current = current.getNext();
}
return false;
}
/**
*Method meant for debugging
*clears the list
*/
public void clear(){
head = null;
tail = null;
}
/*********************************************************/
/**
* Debugging main for class LinkedList.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
LinkedList LL = new LinkedList();
Object[] array;
LinkedList LL2 = new LinkedList();
System.out.println("test 1");
LL.addToFront("2");
LL.addToFront("1");
LL.addToBack("3");
LL.addToBack("4");
LL.listOut();
array = LL.asArray();
for(int i=0; i<array.length; i++){
System.out.println(array[i]);
}
System.out.println("test 2");
LL.removeFromFront();
LL.removeFromBack();
LL.removeFromBack();
array = LL.asArray();
for(int i=0; i<array.length; i++){
System.out.println(array[i]);
}
System.out.println(LL.equals(LL2));
LL.clear();
LL.addToFront("1");
LL.addToFront("2");
LL.addToBack("3");
LL2.addToFront("1");
LL2.addToFront("2");
LL2.addToBack("3");
System.out.println(LL2.equals(LL));
LL.clear();
LL2.clear();
LL.addToBack("2");
LL.addToFront(new Integer(1));
LL2.addToBack("2");
System.out.println(LL.equals(LL2));
LL2.addToFront(new Integer(1));
System.out.println(LL2.equals(LL));
LL2.removeFromBack();
System.out.println(LL2.equals(LL));
System.out.println(LL.equals(LL));
LL.clear();
System.out.println(LL.equals(LL2));
//test what autograder finds as wrong
//431, 653, 95, 201, 331, 326, 627, 38, 284, 350, 960, 36
LL.clear();
LL2.clear();
LL.addToBack(new Integer(36));
LL.addToFront(new Integer(960));
LL.addToFront(new Integer(350));
LL.addToFront(new Integer(284));
LL.addToFront(new Integer(38));
LL.addToFront(new Integer(627));
LL.addToFront(new Integer(326));
LL.addToFront(new Integer(331));
LL.addToFront(new Integer(201));
LL.addToFront(new Integer(95));
LL.addToFront(new Integer(653));
LL.addToFront(new Integer(431));
System.out.println(LL.equals(LL));
System.out.println(LL.equals(LL2));
LL2 = LL;
System.out.println(LL.equals(LL2));
//Holy crap this is a long debug main!
LL2.clear();
LL2.addToFront(new Integer(960));
LL2.addToFront(new Integer(350));
LL2.addToFront(new Integer(284));
LL2.addToFront(new Integer(38));
LL2.addToFront(new Integer(627));
LL2.addToFront(new Integer(326));
LL2.addToFront(new Integer(331));
LL2.addToFront(new Integer(201));
LL2.addToFront(new Integer(95));
LL2.addToFront(new Integer(653));
LL2.addToFront(new Integer(431));
System.out.println(LL.equals(LL2));
}// end of main(String[] args)
}// end of class LinkedList

View File

@@ -0,0 +1,114 @@
/**
* <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

View File

@@ -0,0 +1,35 @@
/**
* <PRE>
* SwimmingType.java
*
* Revisions: 1.0 Sep. 21, 2002
* Created the SwimmingType interface
* 1.1 Sep. 28, 2002
* 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 interface SwimmingType {
/**
*@param depth, the depth to set animal at
*/
public void setDepth(int depth);
/**
*@return the depth of the animal
*/
public int getDepth();
}// end of class SwimmingType

View File

@@ -0,0 +1,535 @@
/**
* CS1322: Programming Assignment #2 - Fall 2002
*
*
* <PRE>
* Class Zoo - A class designed to provide a menu for users to interact
* with to run the Zoo for P2. This class is provided by CS1322,
* for you to modify as needed.
* You should add your collaboration statement, to this ident box below,
* and place your own @author tag below the one given by the author of
* the code given.
* Revisions 1.0: September 15th, 2002
* Received class from CS1322
* 1.1: September 28th, 2002
* Finished Coding
* </PRE>
*
* @author <A HREF="mailto:adhilton@cc.gatech.edu">Andrew Hilton</A>
* @version Version 1.1, September 28th, 2002
*/
import java.io.*;
public class Zoo
{
/**
* This variable contains all of the buildings (Aquariums and
* Aviaries) that are in this Zoo.
*/
private ZooBuilding[] myBuildings;
/**
* This constant specifies the number of buildings in the Zoo.
*/
private static final int NUM_BUILDINGS=6;
/**
* This constant is the main menu choice for putting a new animal
* into the Zoo.
*/
private static final int CHOICE_PUT_ANIMAL=1;
/**
* This constant is the main menu choice for listing the animals
* in the Zoo.
*/
private static final int CHOICE_LIST_ANIMALS=2;
/**
* This constant is the main menu choice for feeding the animals in
* the Zoo.
*/
private static final int CHOICE_FEED_ANIMALS=3;
/**
* This constant is the main menu choice for moving the net in one
* of the Aviaries.
*/
private static final int CHOICE_MOVE_NET=4;
/**
* This constant is the main menu choice for quitting the program.
*/
private static final int CHOICE_QUIT=0;
/**
* This constant specifies the String that is printed to display the
* main menu.
*/
private static final String MAIN_MENU=
"Main Zoo Control\n" +
"----------------\n" +
CHOICE_PUT_ANIMAL+".) Put an animal in a building\n" +
CHOICE_LIST_ANIMALS+".) List the animals in a building\n" +
CHOICE_FEED_ANIMALS+".) Feed the Animals in a building\n" +
CHOICE_MOVE_NET+".) Move the net in an aviary\n"+
CHOICE_QUIT+".) Quit\n"+
"\nEnter your choice: ";
/**
* This constant specifies the animal creation menu choice to make a bat.
*/
private static final int ANIMAL_BAT=1;
/**
* This constant specifies the animal creation menu choice to make a bird.
*/
private static final int ANIMAL_BIRD=2;
/**
* This constant specifies the animal creation menu choice to make a duck.
*/
private static final int ANIMAL_DUCK=3;
/**
* This constant specifies the animal creation menu choice to make a gator.
*/
private static final int ANIMAL_GATOR=4;
/**
* This constant specifies the animal creation menu choice to make a
* goldfish.
*/
private static final int ANIMAL_GOLDFISH=5;
/**
* This constant specifies the animal creation menu choice to make a shark.
*/
private static final int ANIMAL_SHARK=6;
/**
* This constant specifies the String that is displayed for the animal
* creation menu.
*/
private static final String ANIMAL_MENU=
"Choose an Animal Type:\n"+
"----------------------\n"+
ANIMAL_BAT+".) Bat\n"+
ANIMAL_BIRD+".) Bird\n"+
ANIMAL_DUCK+".) Duck\n"+
ANIMAL_GATOR+".) Gator\n"+
ANIMAL_GOLDFISH+".) Goldfish\n"+
ANIMAL_SHARK+".) Shark\n"+
"\nEnter your choice: ";
/**
* The default constructor for Zoo.
* This constructor initializes myBuildings to be an array of
* size NUM_BUILDINGS, then fills it in, alternating between Aviaries
* and Aquariums.
*/
public Zoo()
{
myBuildings=new ZooBuilding[NUM_BUILDINGS];
for(int i=0;i<myBuildings.length;i++)
{
if(i%2==0)
myBuildings[i]=new Aviary("Aviary number "+(i/2+1));
else
myBuildings[i]=new Aquarium("Aquarium number "+ (i/2+1) );
}//for
}//Zoo()
/**
* Reads user input and creates a specified animal.
* This method reads in input from the user to determine what
* type of Animal to make, and then reads the appropriate information
* for that type of Animal.
* @return a newly created Animal that matches the user's specifications,
* or null if the user selects an invalid Animal number
*/
private Animal makeAnimalForUser()
{
System.out.println(ANIMAL_MENU);
int choice= readIntFromUser();
Animal toRet=null;
String name;
String species;
String dangerous;
boolean isDangerous;
int depth;
switch(choice)
{
case ANIMAL_BAT:
name=promptAndRead("Name: ");
toRet=new Bat(name);
break;
case ANIMAL_BIRD:
name=promptAndRead("Name: ");
species=promptAndRead("Species: ");
do
{
dangerous=promptAndRead("Dangerous [Y/N]: ");
}
while(!(dangerous.equalsIgnoreCase("Y")||
dangerous.equalsIgnoreCase("N")));
isDangerous=dangerous.equalsIgnoreCase("Y");
toRet= new Bird(name,species,isDangerous);
break;
case ANIMAL_DUCK:
name=promptAndRead("Name: ");
toRet= new Duck(name);
break;
case ANIMAL_GATOR:
name=promptAndRead("Name: ");
toRet= new Gator(name);
break;
case ANIMAL_GOLDFISH:
name=promptAndRead("Name: ");
System.out.print("Depth: ");
depth=readIntFromUser();
toRet= new GoldFish(name,depth);
break;
case ANIMAL_SHARK:
name=promptAndRead("Name: ");
System.out.print("Depth: ");
depth=readIntFromUser();
toRet= new Shark(name,depth);
break;
default:
System.out.println("That is not a valid animal type");
break;
}
return toRet;
}//makeAnimalForUser
/**
* This method moves the Animals in all of the buildings around
* randomly. In addition to moving the Animals around, this method
* makes Animals become hungry, at random- each with a 75% chance
* of becoming hungry when this method is called.
*/
private void moveAnimalsAround()
{
for(int i=0;i<myBuildings.length;i++)
{
ZooBuilding zb=myBuildings[i];
LinkedList ll=zb.getTheAnimals();
Object[] animalsInList=ll.asArray();
for(int j=0;j<animalsInList.length;j++)
{
if(animalsInList[j] instanceof FlyingType &&
animalsInList[j] instanceof SwimmingType)
{
//this animal can both swim and fly.
//better find out where it is
FlyingType ft=(FlyingType) animalsInList[j];
SwimmingType st = (SwimmingType) animalsInList[j];
int alt=ft.getAltitude();
int depth=st.getDepth();
boolean swimming;
if(alt<=0)
swimming=true;
else
swimming=false;
if(swimming)
{
//if near the water's surface, maybe we take off
//(1/4 chance)
if(depth<=1 &&Math.random()<0.25)
{
st.setDepth(0);
ft.setAltitude((int)(Math.random()*25)+15);
}
else
{
int change=(int)((Math.random()*5)-2);
depth += change;
st.setDepth(depth);
}
}//swimming
else
{
//flying low. maybe we land and swim?
// (1/4 chance)
if(alt <=25 && Math.random()<0.25)
{
ft.setAltitude(0);
st.setDepth(1);
}
else
{
int change=(int)(Math.random()*48)-24;
alt += change;
ft.setAltitude(alt);
}
}//flying
}
else if(animalsInList[j] instanceof FlyingType)
{
FlyingType ft=(FlyingType) animalsInList[j];
int alt=ft.getAltitude();
int change=(int)((Math.random()*20)+(Math.random()*20)-10);
alt += change;
if(alt<0)
{
alt=0;
}
ft.setAltitude(alt);
}//flying
else if(animalsInList[j] instanceof SwimmingType)
{
SwimmingType st=(SwimmingType) animalsInList[j];
//*** YOUR CODE GOES HERE *** (3)
int depth = st.getDepth();
/************/
int change=(int)((Math.random()*30)-12);
depth+=change;
//*** YOUR CODE GOES HERE *** (4)
st.setDepth(depth);
/*****************/
}//swimming
if(animalsInList[j] instanceof Animal)
{
if(Math.random()<0.75) //75% chance of animal getting hungry
{
((Animal)animalsInList[j]).setIsHungry(true);
}
}
else
{
System.err.println("Error: Non-animal in array at index "+
j+"\n found: "+animalsInList[j]);
System.exit(-1);
}
}//for j
}//for i
}//moveAnimalsAround()
/**
* A conveinece method to prompt the user for input and read it.
* Prints the prompt, then reads and returns a line of input.
* @param prompt is the prompt to print
* @return the line of input read from the user.
*/
private static String promptAndRead(String prompt)
{
System.out.print(prompt);
return IOHelper.readLine();
}
/**
* Reads in an int from the user and returns it.
* This method reads lines of input from the user until the user enters
* a valid number. When a valid number is entered, it is converted
* from a String to an int and returned.
* @return the number that the user entered.
*/
private static int readIntFromUser()
{
String line="";
int choice=0;
boolean done=false;
do
{
//***YOUR CODE GOES HERE*** (1)
line = IOHelper.readLine();
//now do conversion of line to an int
try
{
choice=Integer.parseInt(line);
done=true;
}
catch(NumberFormatException nfe)
{
System.out.println("That was not a number! Try again");
}
}
while(!done);
return choice;
}//readIntFromUser()
/**
* Selects a building number.
* Prompts the user to select a building, continues to reprompt
* until a valid building number is entered.
* @return the building number entered by the user
*/
private int chooseBuilding()
{
int choice;
do
{
System.out.print("Enter a building number");
choice=readIntFromUser();
}
while(choice<0|| choice>=myBuildings.length);
return choice;
}//chooseBuilding
/**
* Handles putting a new Animal into the Zoo.
* This method reads input from the user to determine which building the
* Animal should go into. Then it calls makeAnimalForUser() to
* create a new Animal to put in. If the Animal cannot live in that
* type of building, an error is printed and the method returns,
* otherwise the Animal is added to the building.
*/
private void doPutAnimal()
{
int buildingNumber=chooseBuilding();
ZooBuilding zb=myBuildings[buildingNumber];
Animal toAdd=makeAnimalForUser();
if(toAdd==null)
{
return;
}
if(((myBuildings[buildingNumber] instanceof Aviary) &&
!(toAdd instanceof FlyingType))||
((myBuildings[buildingNumber] instanceof Aquarium) &&
!(toAdd instanceof SwimmingType)))
{
System.out.println("That animal cannot live in that building!");
return;
}
//***YOUR CODE GOES HERE *** (5)
zb.getTheAnimals().addToBack(toAdd);
/**********************************/
}//doPutAnimal()
/**
* Lists the animals in a building.
* This method prompts the user for a building number, then
* lists all of the animals in that building.
*/
private void doListAnimals()
{
//*** YOUR CODE GOES HERE *** (6)
int choice = chooseBuilding();
ZooBuilding zb = myBuildings[choice];
Animal temp;
for(int i=0; i<zb.getTheAnimals().size(); i++){
temp = (Animal)zb.getTheAnimals().removeFromFront();
System.out.println(temp);
zb.getTheAnimals().addToBack(temp);
}
}//doListAnimals()
/**
* Feeds the Animals in a building.
* This method prompts the user for a building number and a type of food,
* then feeds that food to the animals in the specified building.
*/
private void doFeedAnimals()
{
int buildingNumber=chooseBuilding();
ZooBuilding zb=myBuildings[buildingNumber];
String food=promptAndRead("What type of food?");
//*** YOUR CODE GOES HERE *** (7)
zb.feedAnimals(food);
}//doFeedAnimals()
/**
*prompt for building, check if its aviary,
*and if it is, add/remove the net
*/
private void doMoveNet()
{
// *** YOUR CODE GOES HERE *** (9)
//Let's do this all in Hungarian Notation :)
//So MS isn't completely useless, eh?
String sEntry;
int iChoice = 0;
boolean bDone = false;
do{
sEntry = promptAndRead("What building?");
try
{
iChoice=Integer.parseInt(sEntry);
bDone=true;
}
catch(NumberFormatException nfe)
{
System.out.println("That was not a number! Try again");
}
}while(!bDone);
if(!(myBuildings[iChoice] instanceof Aviary)){
System.out.println("That building is not an Aviary, it has no net");
return;
}
boolean bNet;
Aviary avTemp = (Aviary)myBuildings[iChoice];
bNet = avTemp.getNetClosed();
if(bNet){
avTemp.setNetClosed(false);
}
else {//!bNet
avTemp.setNetClosed(true);
}
}//doMoveNet
private void showZooStatus()
{
System.out.println("Zoo status");
System.out.println("----------");
for(int i=0;i<myBuildings.length;i++)
{
System.out.println(myBuildings[i]);
if(myBuildings[i].isSafeToEnter())
{
System.out.println("\t Is safe to enter.");
}
else
{
System.out.println("\t Is NOT safe to enter.");
}
System.out.println("\t Has "+myBuildings[i].getHungryAnimals()+
" hungry animals.");
}//for i
}//showZooStatus
/**
* Runs the Zoo simulation.
* This method displays the menu and performs the requested action
* until the user chooses to quit.
*/
private void run()
{
int userChoice;
do
{
moveAnimalsAround();
showZooStatus();
//***YOUR CODE GOES HERE*** (8)
System.out.println(MAIN_MENU);
/****************************/
userChoice=readIntFromUser();
switch(userChoice)
{
case CHOICE_PUT_ANIMAL:
doPutAnimal();
break;
case CHOICE_LIST_ANIMALS:
doListAnimals();
break;
case CHOICE_FEED_ANIMALS:
doFeedAnimals();
break;
//*** YOUR CODE GOES HERE *** (10)
case CHOICE_MOVE_NET:
doMoveNet();
break;
case CHOICE_QUIT:
/* do nothing */
break;
default:
//***YOUR CODE GOES HERE***(2)
System.out.println("That is not a valid choice, try again");
break;
}//switch(userChoice)
}
while(userChoice!= CHOICE_QUIT);
}//run()
/**
* The starting point for the program- makes a new Zoo, and calls
* run() to do the simulation.
* @params args IGNORED.
*/
public static void main(String[] args)
{
Zoo myZoo=new Zoo();
myZoo.run();
}//main()
}//end class Zoo

View 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

498
CS1322/final/Animals/p2.txt Normal file
View File

@@ -0,0 +1,498 @@
CS1322 - Program 2: Its a zoo out there!
===============================================================================
Assigned: Monday, September 18th, 2002
Due: Monday, September 30th, 2002 at 23:59:59
Stop Accepting: Tuesday, October 1st, 2002 at 08:00:00
Phase I Instant Feedback Deadline: Monday, September 23rd, 2002 at 23:59:59
Phase V Instant Feedback Deadline: Monday, September 30th, 2002 at 23:59:59
=======================================================================
TOPICS
=======================================================================
Topics you should understand coming into this assignment:
o Creation and usage of objects and methods
o Iteration and Recursion
o Arrays
Topics that you should understand as a result of doing this assignment:
o Inheritance
o Interfaces
o Polymorphism
o Dynamic Binding
o Linked Lists
o Stacks/Queues
o Constructor Chaining
===============================================================================
Program Overview
===============================================================================
In this program, you are going to be writing code for a zoo. This zoo has
Animals of different types: Sharks, GoldFish, Gators, Birds, Ducks, and Bats.
You will keep track of the Animals in various places via LinkedLists.
-------------------------------------------------------------------------------
Phase 1: Your basic Animals *THIS IS AN INSTANT FEEDBACK PHASE*
This phase should take you no more than 2 hours, 10 minutes to complete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The first step is to make an abstract class Animal.
This class should have the following variables and methods:
public abstract boolean isDangerous();
public abstract void eat(String food);
a private boolean called "isHungry" and appropriate accessor/modifier
(setIsHungry/getIsHungry).
a private String called "name" and appropriate accessor (No modifier).
a .equals method which behaves as follows
- if the parameter passed in is not an Animal, return false
- if the parameter passed in has a different name return false
- if one animal is dangerous and the other is not, return false
- if one animal is hungry and the other is not, return false
- otherwise, return true
a constructor that takes in a name and sets the name variable from it,
and should set isHungry to false.
Next, you should make the following subclasses of Animal:
o Fish, which is abstract
- Fish have an private int depth, with appropriate accessor and
modifier. Since fish cannot swim at a negative depth, anything
less than 0 should be replaced by 0 in the modifier.
- Fish have a .equals method which behaves as follows
* if the parameter passed in is not a Fish, return false
* call the super class's .equals method- if it returns
false, then return false.
* if the parameter passed in is at a different depth,
return false
* otherwise, return true
- Fish have a constructor that takes a name and an initial depth.
They should use super() to call the parent constructor with the name.
o Gator, which is NOT abstract
- Gators are dangerous, so implement the isDangerous() method
appropriately.
- The Gator should implement the eat method to compare the food
passed in to "chicken", "beef", "pork", "human", and "mystery meat",
and if it is one of those, setHungry to false. If the food is
not acceptable, the Gator ignores it and does not change its
isHungry status.
- Gators have a private int depth, with appropriate accessor and
modifier, however, Gators do not swim below 50 feet under the
water- so if a value of more than 50 is passed to the modifier,
it is set to 50. Unlike fish, Gators may come out of the water,
so they can have a negative depth. (A gator at -5 feet under
the water would be on the ground, 5 feet above the water).
- Gators have a .equals method which behaves as follows
* if the parameter passed in is not a Gator, return false
* call the super class's .equals method- if it returns
false, then return false.
* if the parameter passed in is at a different depth,
return false
* otherwise, return true
- Gators have a constructor that takes a name. The super constructor
should be called with this name, and the depth should be set to 0.
- Gators have a toString that returns the following:
A Gator named <name> at depth <depth> which is [hungry/not hungry].
For example,
A Gator named Joe at depth 4 which is hungry.
o Bird, which is NOT abstract
- Some Birds are dangerous, others are not. Make a private instance
variable "dangerous" which is a boolean. Implement isDangerous
to return this value. There should be no modifier for this
variable.
- Birds have a "species" which is a String. This variable should
have an accessor, but no modifier.
- Birds have an "altitude", which is a private int. Make the variable,
accessor, and modifier for altitude.
- Birds have a constructor
public Bird(String name, String species,
boolean dangerous, int alt)
which calls the super constructor and set the variables
appropriately.
- Birds have an eat method which checks if the parameter is
"bird seed", and if so the bird eats it and becomes not hungry.
- Birds have a toString() method that returns the following:
A <species> named <name> at altitude <alt> that is [dangerous/not dangerous]
and is [hungry/not hungry].
For example:
A wren named Chirpy at altitude 50 that is dangerous and hungry.
- Birds have a constructor
public Bird(String name, String species,boolean dangerous)
which chains to the other constructor with an altitude of 0.
- Birds have a .equals method which behaves as follows:
* if the parameter passed in is not a Bird, return false
* call the super class's .equals method- if it returns
false, then return false.
* if the species or altitudes are not the same, return false.
* otherwise, return true.
At this point, you should have written 4 classes- Animal, Fish, Gator,
and Bird. Since Animal and Fish are abstract, you cannot make instances
of them directly, however, you should test Gator and Bird in main methods
inside those classes prior to submitting for instant feedback.
When you think that your code is ready for feedback, submit it as p2-phase1
on WebWork and get feedback.
Reminder: Don't forget about "Add as Zip". Since this program will have
several files to submit, you will want to use this feature. Zip
your java files up, then select the zip file- choose "Add as Zip" instead
of add. WebWork will upload the zip file, then unzip it. When it redisplays
the page, it will list all of the java files that were inside the zip.
Since you do not have to choose each file separately- this will save
you time!
-------------------------------------------------------------------------------
Phase 2: More animals!
This phase should take you no longer than 3 hours, 30 minutes to complete.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At this point, you should have made your Animal, Fish, Gator, and Bird classes
working correctly from getting instant feedback on them- this should also mean
that you are comfortable with
- inheritance
- abstract classes
- .equals methods
- toString methods
Now you are going to write some more Animal types on your own.
For each type, you will write the eat() method similarly to what
was done before. You will simply be given a list of foods that the
Animal will eat.
o Bat is subclass of Animal
- Bats eat "insects"
- Bats are not dangerous [implement isDangerous() accordingly].
- Bats have an altitude, which is an int, with appropriate accessor and
modifier methods.
- A Bat is equal to another Object iff (if and only if) the other object
is a Bat at the same altitude, and the super class's .equals returns
true.
- Bats have a toString() that returns the following:
A Bat named <name> at altitude <alt> that is [hungry/not hungry].
- Bats have a constructor
public Bat(String name)
which chains to the super constructor with their name.
o Shark is a subclass of Fish
- Sharks eat "human", "chicken", and "fish".
- Sharks have a constructor that takes a name and an initial depth.
They should use super() to call the parent constructor with both values.
- Sharks are dangerous [implement isDangerous() accordingly].
- A Shark is equal to another Object iff the other Object is a Shark,
and the superclass .equals returns true.
- Sharks have a toString() that returns the following:
A Shark named <name> at depth <depth> that is [hungry/not hungry].
o GoldFish is a subclass of Fish
- GoldFish eat "fish food"
- GoldFish have a constructor that takes a name and an initial depth.
They should use super() to call the parent constructor with both values.
- GoldFish are not dangerous [implement isDangerous() accordingly].
- A GoldFish is equal to another Object iff the other Object is a GoldFish,
and the superclass .equals returns true.
- GoldFish have a toString() that returns the following:
A GoldFish named <name> at depth <depth> that is [hungry/not hungry].
o Duck is a subclass of Bird
- Ducks use their inherited behavior to eat.
- Ducks can also swim, so they have a depth below the water- the depth
variable should be an int, with appropriate accessor and modifier
[see next item].
- Ducks have a boolean to indicate whether they are swimming or flying.
This boolean should be called "flying" and should have an accessor
ONLY [called isFlying]. The modifier for setAltitude from
the parent class should be overridden to
- set flying to true
- call the method in the parent class
The modifier for depth should
- set the depth appropriately
- set flying to false
- A Duck is equal to another Object iff the other Object is a Duck,
the two Ducks are at the same depth, both are flying or both are
swimming, and the super class's .equals returns true.
- Ducks have a toString that depends on whether the duck is
flying or swimming.
o If the Duck is flying, the toString should simply call the super
class's toString and return the value it returns.
o If the Duck is swimming, the toString should return the following:
A swimming duck named <name> at depth <depth> that is [hungry/not hungry].
- Ducks have a constructor
public Duck(String name)
which chains to the super constructor and passes in the name, the
species "Duck", false for dangerous. After calling the super
constructor, setDepth should be used to set the depth to 0.
At this point, you should have the following concrete [not abstract] classes
which should each have test mains that completely test them:
- Shark
- GoldFish
- Gator
- Bird
- Duck
- Bat
-------------------------------------------------------------------------------
Phase 3: Things that fly and things that swim- Interfaces
This phase should take you no longer than 20 minutes to complete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you notice that many of the Animals had method that were similar?
Go back and look at which Animals can fly [have an altitude] and which Animals
can swim [have a depth].
Flying Animals: Birds (includes Ducks) and Bats
Swimming Animals: Fish (includes Sharks & GoldFish) Gators, and Ducks
Wouldn't it be nice to have a type for things that can fly and a type
for things that can swim? They all have common behaviors, so it seems
logical. One idea would be to make some parent class- maybe have
FlyingAnimal and SwimmingAnimal as abstract subclasses of Animal....
But what about the Ducks? We can only inherit from one class, and
Ducks can both swim and fly! So we need interfaces. Interfaces are
useful in situations where you want to have a type for "all things that
can _________"- in this case, "all things that can fly" and "all things
that can swim". Note that a class is an actual type of object. An interface
is a type also, but it tends to be more for a category of types that
can do similar things. So now we will create two interfaces:
o The FlyingType interface should have two methods in it:
public void setAltitude(int alt);
public int getAltitude();
o The SwimmingType interface should have two methods in it:
public void setDepth(int depth);
public int getDepth();
Now, go back to Bird and Bat- declare them as implementing FlyingType.
Then, go back to Fish, Gator, and Duck- declare each of them as implementing
SwimmingType.
Note that their subclasses automatically implement the interfaces since their
parent classes do.
By this time, you should have the following java files made:
- Animal.java
- Fish.java
- Shark.java
- GoldFish.java
- Gator.java
- Bird.java
- Duck.java
- Bat.java
- FlyingType.java
- SwimmingType.java
-------------------------------------------------------------------------------
Phase 4: Making a LinkedList *THIS IS AN INSTANT FEEDBACK PHASE*
This phase should not take you longer than 4 hours
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now, we are going to move to something slightly different. We have
spent the past three phases creating an inheritance structure for animals.
Now we are going to make a LinkedList that we can use to hold things in
a dynamic data structure. LinkedLists in java are slightly different
from those in scheme, but they have some striking similarities.
- First, you will need to create a class LLNode.
o This class should have two instance variables:
private Object data;
private LLNode next;
Each of these should have an appropriate accessor and modifier.
o There should be three constructors
public LLNode() //both next and data are initialized to null
public LLNode(Object o) //next is initialized to null, data to o
public LLNode(Object o, LLNode next) //both fields initialized from the
//params
o There should be a toString() method which simply returns the
data's toString()
For those of you who took scheme, this should sound quite similar
to a cons cell. Cons cells had "first" and "rest", LLNodes have
"data" and "next".
- Now, create a class LinkedList.
o This class should have two instance variables
private LLNode head;
private LLNode tail;
head should always reference the front (first item) of the list
tail should always reference the back (last item) of the list
o There should be a default constructor which initializes both
variables to null.
o There should be a method
public void addToFront(Object o)
which puts o into a new LLNode and adds it to the front of the list.
When this method returns, head should reference the LLNode containing o.
Tail should reference this node iff it is the only node in the list.
o There should be a method
public void addToBack(Object o)
which puts o into a new LLNode and adds it to the end of the list.
When the method returns, tail should reference the LLNode containing o.
Head should reference this node iff it is the only node in the list.
o There should be a method
public Object getFirst()
which returns [without destroying] the first item in the list.
This should return the data, not the node.
o There should be a method
public Object getLast()
which returns [without destroying] the last item in the list.
This should return the data, not the node.
o There should be a method
public Object removeFromFront()
which removes and returns the first item in the list.
This should return the data, not the node.
o There should be a method
public Object removeFromBack()
which removes and returns the last item in the list.
This should return the data, not the node.
Note that for both removes methods, if the list becomes empty, both
head and tail should be set to null.
o The method
public int size()
which returns a count of the number of items in the list.
o The method
public Object[] asArray()
which returns an array containing all of the items in the list in order.
Element 0 of the array should have the data from the head of the list.
o The .equals method should return true iff the lists are both the
same length and the corresponding elements all are equal to each other
according to their .equals methods. NOTE: THIS SHOULD NOT HAVE ANY
SIDE EFFECTS ON THE LIST. Be VERY CAREFUL NOT TO DESTROY YOUR LIST.
Also: Note that using Strings to compare the lists is NOT a valid
approach. The LinkedList containing the String "1" and the LinkedList
containing the Integer 1 are completely different, but have the
same String representations.
o The toString method should return a String that looks like
[ first elem, second elem, third elem ]
(where "first elem" "second elem" and "third elem" are the
toString()s of the first, second, and third items in a three item
list respectively..)
There should be a "[", followed by the toString() of each data item
in order, separated by commas, and ending with a "]".
o The method
public boolean contains(Object o)
which returns true iff there is an Object in the list that .equals(o).
Test your LinkedList and LLNode classes, then submit LLNode.java and
LinkedList.java for instant feedback as p2-Phase4.
-------------------------------------------------------------------------------
Phase 5: Aviaries and Aquariums.
This phase should not take longer than 1.5 hours
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now we are going to make Aviaries (places where flying things live) to hold
our flying creatures, and Aquariums to hold our swimming creatures.
In our zoo, Aviaries have a net which can be closed across the aviary at 75
feet up. It is safe to enter an aviary (to feed animals etc) iff the net
is closed, and all dangerous animals are above it. It is safe to enter
an Aquarium iff all dangerous animals are below 30 feet deep.
Note that you may assume that only FlyingType Animals live in Aviaries,
and only SwimmingType Animals live in Aquariums.
- Make an abstract class ZooBuilding which has
- public abstract boolean isSafeToEnter()
- a private LinkedList called "theAnimals"
- an accessor for theAnimals (no modifier)
- a private String for name
- an accessor for name (no modifier)
- a constructor which takes in a name, sets the name variable to
that name and initializes theAnimals to a new LinkedList.
- public int getHungryAnimals()
which returns a count of how many hungry animals are in the Zoo.
- public void feedAnimals(String food)
this method first checks if it is safe to enter the building.
if it is not safe, this method should print
"The building is unsafe to enter!" and then return.
if it is safe, it should call make all Animals eat() the food
passed in (some of them will not like it, but that is their
choice)
- Make a class Aviary which is a subclass of ZooBuilding and has
- an instance variable (with accessors and modifiers) called netClosed
which is a boolean. The accessor should be called getNetClosed
and the modifier should be called setNetClosed.
- the method
public boolean isSafeToEnter()
which returns true if the building is safe to enter, false if
not- according to the criteria above.
- a constructor which takes the name and chains to the super constructor
- a toString() method which returns
An Aviary named <name>.
- Make a class Aquarium which is a subclass of ZooBuilding and has
- the method
public boolean isSafeToEnter()
which returns true if the building is safe to enter, false if
not- according to the criteria above.
- a constructor which takes the name and chains to the super constructor
- a toString() method which returns
An Aquarium named <name>.
Be sure to test your Aviary and Aquarium completely before proceeding to
phase 6.
-------------------------------------------------------------------------------
Phase 6:
This phase should not take longer than 1 hour
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In this phase, you will be making a menu to control your program.
Since we have not covered IO yet, most of this code is given to you.
-> Open and look over Zoo.java <-
Zoo.java contains a mostly complete implementation of the zoo menu.
You only have to do a few things.
Look for the places that say
//***YOUR CODE GOES HERE*** (some number)
These are where you will be adding code to this file. The directions
below are numbered to match the numbers in those comments.
1. Use IOHelper.readLine() to read a line of input from the user.
Store that line of input into the "line variable".
2. Print out the message "That is not a valid choice, try again"
when the user's selection is not valid.
3. Replace the line
int depth=0;
with the appropriate line of code to get the depth from the current
SwimmingType animal.
4. Add a line of code to set the depth of the current SwimmingType
animal to be depth.
5. Add the Animal that the user created (toAdd) to the selected building
(zb).
6. Prompt the user to select a building, then list all of the animals
in the building by printing the toString() of its LinkedList of
animals. When prompting for a building, find and use the method
in Zoo specifically designed for that.
7. Use the food (food)that the user picked to feed the animals in the selected
building (zb).
8. Print the menu (find the appropriate constant).
9. Fill in (and javadoc!) the method doMoveNet() so that it
- prompts for a building number
- checks if the building is an Aviary
- if the building is not an Aviary, print
"That building is not an Aviary, it has no net"
- otherwise toggle (change true to false, false to true) the
value of the netClosed on that aviary.
10. Add a case to the menu switch case statement to handle the choice
for moving the net. Be sure to use the appropriate constant.
------------------------------------------------------------------------------
DON'T FORGET TO SUBMIT AS P2 SO YOUR ASSIGNMENT WILL BE GRADED.
ALSO- DON'T FORGET TO PRACTICE "SAFE SUBMIT"
Files to turnin for p2 [make a zip file and use "Add as Zip", since there are
17 files to submit- it will be much faster for you].
Animal.java
Fish.java
Shark.java
GoldFish.java
Gator.java
Bird.java
Bat.java
Duck.java
FlyingType.java
SwimmingType.java
LLNode.java
LinkedList.java
ZooBuilding.java
Aquarium.java
Aviary.java
Zoo.java
IOHelper.java
[any other files needed to make your submission compile and run]

3
CS1322/final/Fish.java Normal file
View File

@@ -0,0 +1,3 @@
public class Fish extends Animal implements UnderwaterType{
public void submerge(){}
}

6
CS1322/final/Test.java Normal file
View File

@@ -0,0 +1,6 @@
public class Test{
public void main(String srgs[]){
Animal a = new Fish();
a.submerge();
}
}

View File

@@ -0,0 +1,3 @@
public interface UnderwaterType{
public void submerge();
}

View File

@@ -0,0 +1,382 @@
This survey is intended to help us understand your opinions about CS
1322. Please answer the questions honestly and openly. We value your
views about the course, and we will use feedback from this survey in
the future. For multiple choice questions, please circle the
letter/number of your reply. If you have additional comments for which
you do not have space, please feel free to attach other pages.
Term: Fall 2002 Your major: __________________________
1. OVERALL
Your lecturer: _________________
Which lecturer's class did you attend most often? ________________
Your TA: __________________________
Most previous CS course experience
1) Took CS1 Pseudocode
2) Took CS1 Scheme
3) Took CS1-X Accelerated Scheme
4) Transfer student (Language used: _______________________________)
5) Already took 1322 before
Grade received in that course: _______________
Academic year?
Freshman Sophomore Junior Senior Graduate
What were the best things about this course?
What were the worst things about this course?
----------------------------------------------------------------------
2. LECTURE
What percentage of class lectures did you attend? ________________
If you did not attend class regularly, why?
In your opinion, how important is attending lecture to doing well in
class?
1) Does not matter
2) It has a small impact
3) It is moderately important
4) It is quite important
5) It is absolutely essential
Please rate your lecturer's teaching ability
1) Very Good
2) Good
3) OK
4) Bad
5) Very Bad
Please critique your lecturer's in-class teaching abilities,
presentation skills, etc.:
----------------------------------------------------------------------
3. RECITATION
What percentage of recitations, excluding test dates, did you attend?
________________
In your opinion, how important is attending recitation to doing well in
class?
1) Does not matter
2) It has a small impact
3) It is moderately important
4) It is quite important
5) It is absolutely essential
How effective were the TAs in teaching recitation?
1) I would not know; I did not attend recitations beyond tests.
2) They could not explain things very well.
3) They were OK. Some things were clear, some weren't.
4) They did a good job overall.
5) Outstanding. I learned most of the course material from them.
----------------------------------------------------------------------
4. TEACHING ASSISTANTS
Please rate your TA's teaching ability
1) Very Good
2) Good
3) OK
4) Bad
5) Very Bad
Write any comments about your TA's teaching ability, etc. that you
feel you should share with us.
How much time did you spend with your TA each week?
1) Very little or no time
2) Less than 15 minutes
3) About a half hour
4) About an hour
5) Several hours
Characterize the quality of the assistance provided by your TA, in general.
1) Not helpful; could not provide assistance at all
2) Somewhat helpful, often not able to provide assistance
3) Mostly helpful, often provided valuable assistance
4) Very helpful, always could help you make progress
Where there any other TAs that you found particularly helpful
(ie during lab hours, etc)
----------------------------------------------------------------------
5. EVALUATION MATERIALS
I felt the programming assignments were
1) Extremely boring
2) Somewhat boring
3) So-so
4) Fairly interesting
5) Very interesting
During tests, I was ...
1) Unable to answer all the questions in the given time
2) Always rushed for time, but able to complete the test
3) Sometimes rushed for time, but able to complete
4) Able to complete the test in time
5) Able to leave early
I felt the tests were
1) Too easy
2) Easier than expected
3) About what I expected
4) More difficult than expected
5) Too difficult
Please characterize the practice test materials
1) What? There were practice tests?
2) They were not helpful
3) They were somewhat helpful in preparation for tests
4) They were very helpful in preparation for tests
5) They were all I studied for the tests
Please characterize the autograding tools:
1) Autograding was not useful; there's no need for it in the future
2) Autograding was useful in debugging my programs, but not essential
3) Autograding was fairly useful; it caught many mistakes
4) Autograding was an essential part of my learning
Please provide below any comments that you have concerning any of the
evaluation materials mentioned above (tests, programs, practice
tests, autograder):
----------------------------------------------------------------------
6. RESOURCES
Please characterize how much you used each of the course resources
listed below on the following scale:
1 2 3 4 5
Never Used it Used it Used it Used it
used it not often moderately often extensively
______ Weiss textbook
______ Some other book(s)
______ Lecture slides
______ Lectures
______ Recitations
______ Newsgroup
______ Collaborations with other students
______ TAs
______ Other: _________________
Please characterize the usefulness (value for learning) of each of
the course resources listed below on the following scale:
1 2 3 4 5
Useless Not very Moderately Very Essential
useful useful useful
______ Weiss textbook
______ Some other book(s)
______ Lecture slides
______ Lectures
______ Recitations
______ Newsgroup
______ Collaborations with other students
______ TAs
______ Other: _________________
----------------------------------------------------------------------
7. COLLABORATION
How did you work on your programs?
1) I worked alone
2) I did my own work, but assisted others
3) I worked with a group, but did my own coding
4) I worked with a group, and we all coded together
5) I worked with a group, but relied on others for much of the coding
6) I got mostly complete programs from others to turn in
If you had to code the assigments over again, today, all alone,
could you do it without collaboration?
1) Sure, no problem
2) Yes, but it would take a little effort
3) With some difficulty
4) With great difficulty
5) No way
What did you think of the collaboration policy in this course?
Please provide any pertinent comments below:
----------------------------------------------------------------------
8. OVERALL
How would you describe your programming abilities, after CS 1322?
1) I'm still not a very good programmer
2) I learned a few things, but I'm don't feel comfortable coding
3) I'm OK---I could write programs for other classes
4) I can (truthfully) put down Java programming on a resume
5) I'm on the verge of becoming a java god
Please characterize the workload of this course
1) Very light, no problem
2) Less than other comparable GT courses
3) Reasonable, similar to other comparable GT courses
4) Higher than other comparable GT courses
5) Extreme, very burdensome
What grade do you expect in the course?
________
What were the most important things that you learned from this course?
If you had a friend enrolling in CS 1322, what advice would you give
them about the course and how to succeed?

File diff suppressed because it is too large Load Diff

Binary file not shown.

9
CS1322/final/final.java Normal file
View File

@@ -0,0 +1,9 @@
public class finals{
public static void main(String srgs[]){
char c= (char)( '2' + 5);
System.out.println(c);
int x = '4' / '5';
System.out.println(x);
}
}

9
CS1322/final/finals.java Normal file
View File

@@ -0,0 +1,9 @@
public class finals{
public static void main(String srgs[]){
char c= (char)( '2' + 5);
System.out.println(c);
int x = '4' / '5';
System.out.println(x);
}
}