LivingThing super Class Insect and Animal Class Implementation Practice Problem Question in Java & C++
Implement a superclass LivingThing, then create two classes, Insect and Animal, that inherit from LivingThing. A LivingThing has a species and a bloodType(warm or cold blooded). A Animal has a type(carnivore, herbivore or omnivore), and an Insect has a numLegs. All instance variables must be declared private! Use the following specification to write the class definitions for all the classes. Make sure you include the methods toStringfor all classes.
The LivingThing class is described as follows:
Two attributes:
species: Stores String representing species the LivingThing belongs to
bloodType: Stores a string. ("warm" or "cold")
One constructor:
public LivingThing(String species, String bloodType): Creates a living thing with the specified attributes.
Four methods:
getSpecies(): Returns the species of the livingthing
getBloodType(): Returns a string representing the bloodtype of the thing. ("warm" or "cold")
toString(): Returns a String containing the bloodType followed by the constant String " blooded thing belonging to specie " followed by the specie the thing belongs to.
equals(Object obj): Returns true if this object is equal both in specie and bloodType.
The Animal class is described as follows
One attribute:
type: Can be "carnivore", "omnivore" or "herbivore".
One constructor:
public Animal(String species, String bloodType, String type): Creates an Animal with the specified attributes.
Two methods:
getType(): Returns the type of Animal
toString(): Returns a String containing the bloodType followed by the constant String " blooded thing belonging to specie " followed by the specie the thing belongs tofollowed by the string " which is " followed by the type.
The Insect class is described as follows:
One attribute:
numLegs: Stores an integer representing the number of legs the insect has.
One constructor:
public Insect(String species, String bloodType, int salary): Creates an Insect with the specified attributes.
Two methods:
getNumLegs(): Returns the number of legs of the Insect.
toString(): Returns a String containing the bloodType followed by the constant String " blooded thing belonging to specie " followed by the specie the thing belongs tofollowed by the string " and has " followed by the number of legs followed by " legs".
The code you need to test the Lab is uploaded on the course website. File name is TestLivingThings.java