////////////////////////// Elephant Class Example A ////////////////////////////////
import java.io.*;
class Elephant extends Animal {
/** 3 variables to hold information about our elephant */
private boolean hasTusks;
private int trunkLength;
private String type;
/** Empty "default" constructor" */
Elephant() {
super();
}
/** Constructor initializes our variables with the incoming parameters values of the same name */
Elephant(int height, int weight, int lifespan, boolean hasTusks, int trunkLength, String type) {
super(height, weight, lifespan);
this.hasTusks = hasTusks;
this.trunkLength = trunkLength;
this.type = type;
}
/** Set methods for all of our varaibles to change our information */
public void setHasTusks(boolean hasTusks) {
this.hasTusks = hasTusks;
}
public void setTrunkLength(int trunkLength) {
this.trunkLength = trunkLength;
}
public void setType(String type) {
this.type = type;
}
/** Get methods for all of our varaibles to retrieve our information */
public boolean getHasTusks() {
return hasTusks;
}
public int getTrunkLength() {
return trunkLength;
}
public String getType() {
return type;
}
/** method allows our elephant to "sleep" (Overrides sleep method in the superclass, Animal) */
public void sleep(int howLong) {
for (int x = 0; x < howLong; x++) {
System.out.println("The Elephant is Sleeping now");
}
}
};