Part A: Create a class named Insect, which includes the following: 1. Attributes including: a. A String named species b. A double named weight 2. Get and Set methods for both attributes 3. A default constructor that initializes species to "NA" and weight to 0.0 4. A non-default constructor that takes a String and double argument and defines the corresponding attributes as those values. 5. A method named eat, which increases the weight by 1. Part B: Create a subclass of the class Insect named Butterfly. 1. Include another double attribute named maxWeightToFly 2. Include get and set methods for this new attribute 3. Include a default constructor that initializes species to "NA", weight to 0.0, and maxWeightToFly to 0.0 4. Include a non-default constructor that takes a String and two double arguments and defines the corresponding attributes to those values. 5. Override the eat method so that it increases the weight by 0.5 instead of 1 6. Include a new method named isAbleToFly which compares the weight of the Butterfly to the maxWeightToFly. If the weight attribute is greater than the maxWeightToFly, it returns false. If the weight attribute is less than or equal to maxWeightToFly, it returns true
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Part A:
Create a class named Insect, which includes the following:
1. Attributes including:
a. A String named species
b. A double named weight
2. Get and Set methods for both attributes
3. A default constructor that initializes species to "NA" and weight to 0.0
4. A non-default constructor that takes a String and double argument and defines the corresponding attributes as those values.
5. A method named eat, which increases the weight by 1.
Part B:
Create a subclass of the class Insect named Butterfly.
1. Include another double attribute named maxWeightToFly
2. Include get and set methods for this new attribute
3. Include a default constructor that initializes species to "NA", weight to 0.0, and maxWeightToFly to 0.0
4. Include a non-default constructor that takes a String and two double arguments and defines the corresponding attributes to those values.
5. Override the eat method so that it increases the weight by 0.5 instead of 1
6. Include a new method named isAbleToFly which compares the weight of the Butterfly to the maxWeightToFly. If the weight attribute is greater than the maxWeightToFly, it returns false. If the weight attribute is less than or equal to maxWeightToFly, it returns true.
Step by step
Solved in 3 steps with 2 images