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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

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.

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage