0 puistel Q3) The figure on the next page shows the Animal, Plant classes and th
ID: 3606982 • Letter: 0
Question
0 puistel Q3) The figure on the next page shows the Animal, Plant classes and the Edible interface hierarchies. These classes are the parents of the classes described below: The Animal class is non abstract and defines two functions getlifespan )s getlheartRate), as shown in the figure above. The Plant class defines two abstract functions get.Nane ()&getGroup; ().This class also defines one non abstract function isSeeded), as shown in the figure. The Animal class has two non-abstract child classes: Ant, and Shrimp. The Ant class defines a single function as in the figure, and has one child class, FireAnt. -The Plant class has two non-abstract child classes, Okra and Poisonlvy Interface Edible defines a single function as in the figure Interface Dangerous defines a single function as in the figure. Interface Poisonous is a child of Dangerous and defines a single function as in the figure. The classes Shrimp&Okra; implement the Edible interface Class FirAnt implements the Dangerous interface, and class Poisonlvy implements the Polsonous interface. From the description above, complete the following 1- Using function and class names exactby as given in the description and figures above, create Java classes to design and represent this hierarchy. Place these files inside the Test 2 directory. Besides the files created for this test, there should be no other files of any type in theTest 2 directory 2 For each class, define two constructors: a default, no-argument constructor, and a constructor that assign values to all the member variables, including the variables defined in the class's parent, if any. 3- Adding getter and setter methods in addition to the ones in the figure is entirely optional; however you can only use constructors to assign values to class instance variables from your Driver.java test program 4- Use function return types exactly as given in the figure.Explanation / Answer
// package is Test2. Please create Test2 package and put all interfaces and classes in that package
//1.Animal.java
//package Test2
public class Animal {
public String getLifeSpan(){
return "";
}
public int getHeartRate(){
return 0;
}
}
//2.
//package Test2;
public class Ant {
public int getColonySize(){
return 0;
}
}
//3
//package Test2;
public interface Dangerous {
public boolean isFatal();
}
//4.
//package Test2;
public interface Edible {
public String getTaste();
}
//5.
//package Test2;
public class FireAnt extends Ant implements Dangerous{
public String getHabitat(){
return "";
}
@Override
public boolean isFatal() {
// TODO Auto-generated method stub
return false;
}
}
//6.
//package Test2;
public class Okra extends Plant implements Edible {
@Override
public String getTaste() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getGroup() {
// TODO Auto-generated method stub
return null;
}
}
//7.
//package Test2;
public abstract class Plant {
public abstract String getName();
public abstract String getGroup();
public boolean isSeeded(){
return false;
}
}
//8.
//package Test2;
public class Poisonivy extends Plant implements Poisonous {
@Override
public boolean isFatal() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getTreatment() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getGroup() {
// TODO Auto-generated method stub
return null;
}
}
//9.
//package Test2;
public interface Poisonous extends Dangerous {
public String getTreatment();
}
//10.
//package Test2;
public class Shrmp extends Animal implements Edible {
@Override
public String getTaste() {
return null;
}
}
// Based on your requirement I created only classes. Please put all classes in one package
//Otherwise, get errors.
// There are no any data members showing, that's why didn't create any data members
//So, without data members, getters and setters not possible.
// If u have any doubt or any update code please comment.
// I will add based on requirements.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.