Sei sulla pagina 1di 2

package animal; public class Animal { // set up private instance variables for the animal's name, type, weight

and age public Animal(String nam, String typ, int wt) { //constructor method when the animal's name, type and weight are passed as parameters } public Animal(String nam, String typ, int wt, int yrs) { //constructor method when the animal type, size, and age are pas sed as parameters } //Create four modifier methods to modify each of the instance variables. public void setName(String n) { //set the instance variable } //Create four accessor methods to retrieve each of the instance variable s. public String getName() { //return the animal name } public boolean isLarger(Animal other) { //return whether the animal is bigger than another animal } public boolean typesTheSame(Animal other) { //return whether the animal types are the same } public int differenceInAge(Animal other) { //return difference in age of the two animals } public String toString() { //return the name, type, size, and age of the animal

} }

Potrebbero piacerti anche