////////////////////////// Animal Class Example F ////////////////////////////////
import java.io.*;
class Animal {
/** 3 numeric variables to hold our information */
private int height;
private int weight;
private int lifespan;
/** Empty "default" constructor" */
Animal() {
}
/** Constructor initializes our 3 variables with the three incoming parameter values of the same name */
Animal(int height, int weight, int lifespan) {
this.height = height;
this.weight = weight;
this.lifespan = lifespan;
}
/** Set methods for all of our varaibles to change our information */
public void setHeight(int height) {
this.height = height;
}
public void setWeight(int weight) {
this.weight = weight;
}
public void setLifespan(int lifespan) {
this.lifespan = lifespan;
}
/** Get methods for all of our varaibles to retrieve our information */
public int getHeight() {
return height;
}
public int getWeight() {
return weight;
}
public int getLifespan() {
return lifespan;
}
/** method allows our animal to "eat" (Just prints out "Im eating now") */
public void eat() {
System.out.println("I'm eating now");
}
/** method accepts a numeric value (howLong) to control a loop that will print out "Im sleeping now" as many times as the number entered */
public void sleep(int howLong) {
for (int x = 0; x < howLong; x++) {
System.out.println("I'm Sleeping now");
}
}
};