Question: Using the code sent to you, ensure that it is appropriately utilizing inheritance and polymorphism. If necessary, modify the code to establish a clear inheritance
Using the code sent to you, ensure that it is appropriately utilizing inheritance and polymorphism. If necessary, modify the code to establish a clear inheritance hierarchy and demonstrate polymorphic behavior. Then, design and implement a way to incorporate recursion and Exception handling. You must handle all possible errors appropriately. I will try to break your code. Use recursion by creating a makeSound method that calls a recursive method called recursiveSoundint repetitions The recursiveSound method should print the sound the animal makes the specified number of times.
Animal class: public abstract class Animal
public String type;
public String sound;
AnimalString sound, String type
this.sound sound;
this.type type;
public abstract void setTypeString type;
public abstract String getType;
public abstract void setSoundString sound;
public abstract String getSound;
public String toString
return getType getSound;
animal driver: public class AnimalDriver
public static void mainString args
Mammal pig new Mammaloink"pig";
System.out.printlnA pig.getType goes pig.getSound;
Mammal dog new Mammalwoof"dog";
System.out.printlnA dog.getType goes dog.getSound;
Mammal cat new Mammalmeow"cat";
System.out.printlnA cat.getType goes cat.getSound;
mammal class:public class Mammal extends Animal
public MammalString type, String sound
supertypesound;
@Override
public void setTypeString type
this.type type;
@Override
public String getType
return type;
@Override
public void setSoundString sound
this.sound sound;
@Override
public String getSound
return sound;
Ublic String getSu perString
return super.toString;
sing the code sent to you, ensure that it is appropriately utilizing inheritance and polymorphism. If necessary, modify the code to establish a clear inheritance hierarchy and demonstrate polymorphic behavior. Then, design and implement a way to incorporate recursion and Exception handling. You must handle all possible errors appropriately. I will try to break your code. Use recursion by creating a makeSound method that calls a recursive method called recursiveSoundint repetitions The recursiveSound method should print the sound the animal makes the specified number of times.
Animal class: public abstract class Animal
public String type;
public String sound;
AnimalString sound, String type
this.sound sound;
this.type type;
public abstract void setTypeString type;
public abstract String getType;
public abstract void setSoundString sound;
public abstract String getSound;
public String toString
return getType getSound;
animal driver: public class AnimalDriver
public static void mainString args
Mammal pig new Mammaloink"pig";
System.out.printlnA pig.getType goes pig.getSound;
Mammal dog new Mammalwoof"dog";
System.out.printlnA dog.getType goes dog.getSound;
Mammal cat new Mammalmeow"cat";
System.out.printlnA cat.getType goes cat.getSound;
mammal class:public class Mammal extends Animal
public MammalString type, String sound
supertypesound;
@Override
public void setTypeString type
this.type type;
@Override
public String getType
return type;
@Override
public void setSoundString sound
this.sound sound;
@Override
public String getSound
return sound;
I have everything mostly done. I need to figure out the recursive method and the exception handling.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
