Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create The Four required classes: Animal class– contains four instance variables

ID: 3752899 • Letter: C

Question

Create The Four required classes:

Animal class– contains four instance variables (legs and eyes are integers ) and (eat and sound are strings). All of instance variables (4) Protected.

Have two constructors: one that accepts no parameters and will have the four instance variables assigned to either 0 or “nothing”, appropriately. The other will accept four incoming parameters and will set the instance variables appropriateley to the values of the incoming parameters.

This class will also have a method named printAnimal that has no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like “From Animal: ” to indicate that the printing is being conducted within the class Animal. This method will not return anything.

Finally, there will be a method called setLegs that accepts one incoming parameter and will assign its value to the instance variable legs. This method will not return anything. You are now to do the following sequence of statements:

Spider class – this will be a subclass (child) of the super class Animal (parent). No instance variables are declared.

You will have two constructors: one will accept no parameters. The other will accept four incoming parameters. Both constructors will invoke the parent constructor (i.e. of the Animal class) appropriately.

This class will also have a method called printAnimal that will override the method with the same name within the class Animal. This method will also have no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like “From

Spider: ” to indicate that the printing is being conducted within the class Spider. Also, this method must invoke the method printAnimal within the superclass/parent (i.e. Animal class). This method will not return anything.

This class will have another method called getNumEyes that will have no incoming parameters but will return the value of the instance variable eyes.

This class will have another method called setLegs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parent’s (i.e. Animal class) own method setLegs to do this task. This method will not return anything.

Lion class – this will be a subclass (child) of the super class Animal (parent). No instance variables are declared.

You will have one constructor: It will accept four incoming parameters. This constructor will invoke the parent constructor (i.e. of the Animal class) appropriately.

This class will also have a method called printAnimal that will override the method with the same name within the class Animal. This method will also have no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like “From Lion:” to indicate that the printing is being conducted within the class Lion. Also, this method must invoke the method printAnimal within the superclass/parent (i.e. Animal class). This method will not return anything.

This class will have another method called getNumEyes that will have no incoming parameters but will return the value of the instance variable eyes.

This class will have another method called setLegs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parent’s (i.e. Animal class) own method setLegs to do this task. This method will not return anything.

This class will have another method called setEyes that will accept one incoming parameter. This method will then set the value of the instance variable eyes to the value of the incoming parameter. This method will not return anything.

AnimalTester class – this class will contain your main method. You will instantiate two Spider objects (spidy1 and spidy2, respectively). spidy1 will not have any arguments to the constructor. spidy2 will have the following values sent to the constructor: 8, 8, “insects”, “very quiet”. These values represent the number of legs, the number of eyes, what it eats, and the sound that it makes. You also need to instantiate a Lionobject (lion). lion will have the following values sent to the constructor: 2, 1, “meat”, “roar”. These values represent same thing mentioned above.

Finally, there will be a method called setLegs that accepts one incoming parameter and will assign its value to the instance variable legs. This method will not return anything. You are now to do the following sequence of statements:

Print out the message “Going to print out info about spidy1”

For spidy1 invoke the method printAnimal

Print out the message “Going to print out info about spidy2”

For spidy2 invoke the method printAnimal

Print out a message on how many eyes spidy1 has

Print out a message on how many eyes spidy2 has

For spidy1 set its legs to the number 7

Print out the message “Going to print out info about spidy1”

For spidy1 invoke the method printAnimal

Print out the message “Going to print out info about lion”

For lion invoke the method printAnimal

For lion set its legs to the number 4

Print out the message “Going to print out info about lion”

For lion invoke the method printAnimal

For lion set its eyes to the number 2

Print out the message “Going to print out info about lion”

For lion invoke the method printAnimal

Explanation / Answer

Note : I will add more code to this.Thank You

_______________

Animal.java

public class Animal {

protected int legs;

protected int eyes;

protected String eat;

protected String sound;

public Animal() {

this.legs = 0;

this.eyes = 0;

this.eat = "nothing";

this.sound = "nothing";

}

public Animal(int legs, int eyes, String eat, String sound) {

this.legs = legs;

this.eyes = eyes;

this.eat = eat;

this.sound = sound;

}

public void printAnimal() {

System.out.println("From animal Legs = " + legs + " Eyes = " + eyes

+ " eat = " + eat + " sound = " + sound);

}

public int getLegs() {

return legs;

}

public void setLegs(int legs) {

this.legs = legs;

}

public int getEyes() {

return eyes;

}

public void setEyes(int eyes) {

this.eyes = eyes;

}

public String getEat() {

return eat;

}

public void setEat(String eat) {

this.eat = eat;

}

public String getSound() {

return sound;

}

public void setSound(String sound) {

this.sound = sound;

}

}

________________

Spider.java

public class Spider extends Animal {

public Spider() {

}

public Spider(int legs, int eyes, String eat, String sound) {

super(legs, eyes, eat, sound);

}

public void printAnimal() {

System.out.println("From Spider Legs = " + legs + " Eyes = " + eyes

+ " eat = " + eat + " sound = " + sound);

}

public int getNumEyes()

{

return eyes;

}

public void setLegs(int legs) {

super.setLegs(legs);

}

}

___________________