SlideShare a Scribd company logo
1 of 3
Download to read offline
1)- Create a specialized version of Insects called FlyingInsects which have the ability to fly.
2)- Create a specialized version of Insects called Butterfly which has a state called cocoon and
the
ability of metamorphosis
cocoon is an object of class Cacoon which contains only a toString method which
returns the string “Cacoon” (same as class Stinger in Listing C)
metamorphosis contains a println which utilizes cacoon (same as protectHive in
Listing C)
3)- Refactor the Honeybee and Grasshopper classes into the new hierarchy:
honeybees and butterflies can fly while grasshoppers cannot
4)- Modify the BugCollection main program to instantiate a Butterfly object and to call all
methods
of all Insect subclasses
insect.java
class bodysection
{
private String name;
public bodysection(String s)
{
name = s;
}
public String toString()
{
return name;
}
public class insect
{
private bodysection head;
private bodysection thorax;
private bodysection abdomen;
public insect()
{
head = new bodysection("head");
thorax = new bodysection("thorax");
abdomen = new bodysection("abdomen");
}
public void respireLungs()
{
System.out.println("An insect respires through lungs" + " in its " + thorax);
}
public void reproduceEggs()
{
System.out.println("An insect reproduces by laying eggs" + " from its " + abdomen);
}
}
Solution
import java.util.Scanner;
insect.java
class bodysection
/**
* This class encapsulates the logic and state for a simplified
{
private String name;
public bodysection(String s)
{
name = s;
}
public String toString()
{
return name;
}
public class insect
{
private bodysection head;
private bodysection thorax;
private bodysection abdomen;
public insect()
{
head = new bodysection("head");
thorax = new bodysection("thorax");
abdomen = new bodysection("abdomen");
}
public void respireLungs()
{
System.out.println("An insect respires through lungs" + " in its " + thorax);
}
public void reproduceEggs()
{
System.out.println("An insect reproduces by laying eggs" + " from its " + abdomen);
}
}

More Related Content

More from Footageetoffe16

The owner of a small business is planning on expanding his business. .pdf
The owner of a small business is planning on expanding his business. .pdfThe owner of a small business is planning on expanding his business. .pdf
The owner of a small business is planning on expanding his business. .pdfFootageetoffe16
 
The government safety net creates an adverse selection problem and m.pdf
The government safety net creates an adverse selection problem and m.pdfThe government safety net creates an adverse selection problem and m.pdf
The government safety net creates an adverse selection problem and m.pdfFootageetoffe16
 
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdf
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdfSyntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdf
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdfFootageetoffe16
 
scene from American Samoa Paradise Lost •How does power, both form.pdf
scene from American Samoa Paradise Lost •How does power, both form.pdfscene from American Samoa Paradise Lost •How does power, both form.pdf
scene from American Samoa Paradise Lost •How does power, both form.pdfFootageetoffe16
 
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdf
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdfQUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdf
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdfFootageetoffe16
 
Problems2. This is a map for a diploid plantR--------35-------.pdf
Problems2. This is a map for a diploid plantR--------35-------.pdfProblems2. This is a map for a diploid plantR--------35-------.pdf
Problems2. This is a map for a diploid plantR--------35-------.pdfFootageetoffe16
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfFootageetoffe16
 
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdf
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdfPLEASE PLEASE use you own words, do not copy and paste !!!This is .pdf
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdfFootageetoffe16
 
List the limitations of the GDP. Which one is most importantSol.pdf
List the limitations of the GDP. Which one is most importantSol.pdfList the limitations of the GDP. Which one is most importantSol.pdf
List the limitations of the GDP. Which one is most importantSol.pdfFootageetoffe16
 
Information is given about a polynomial f(x) whose coefficients are r.pdf
Information is given about a polynomial f(x) whose coefficients are r.pdfInformation is given about a polynomial f(x) whose coefficients are r.pdf
Information is given about a polynomial f(x) whose coefficients are r.pdfFootageetoffe16
 
I need to create two binary search trees in Ruby. One using recursio.pdf
I need to create two binary search trees in Ruby. One using recursio.pdfI need to create two binary search trees in Ruby. One using recursio.pdf
I need to create two binary search trees in Ruby. One using recursio.pdfFootageetoffe16
 
I am studying gut flora and had a few questions.Can you discribe a.pdf
I am studying gut flora and had a few questions.Can you discribe a.pdfI am studying gut flora and had a few questions.Can you discribe a.pdf
I am studying gut flora and had a few questions.Can you discribe a.pdfFootageetoffe16
 
httpswww.aitp.orgnews98451 Security Administration and Acces.pdf
httpswww.aitp.orgnews98451 Security Administration and Acces.pdfhttpswww.aitp.orgnews98451 Security Administration and Acces.pdf
httpswww.aitp.orgnews98451 Security Administration and Acces.pdfFootageetoffe16
 
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdf
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdfHwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdf
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdfFootageetoffe16
 
Hint 1 2D array of type Button, all buttons hidden except for one.pdf
Hint 1 2D array of type Button, all buttons hidden except for one.pdfHint 1 2D array of type Button, all buttons hidden except for one.pdf
Hint 1 2D array of type Button, all buttons hidden except for one.pdfFootageetoffe16
 
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdf
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdfExplain in 3 - 5 paragraphs what different skills and workstyles do .pdf
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdfFootageetoffe16
 
Describe your supervisors ability and style of communication. Do y.pdf
Describe your supervisors ability and style of communication. Do y.pdfDescribe your supervisors ability and style of communication. Do y.pdf
Describe your supervisors ability and style of communication. Do y.pdfFootageetoffe16
 
Design a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdfDesign a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdfFootageetoffe16
 
complete a correlation matrix of the four Interpersonal Strategies a.pdf
complete a correlation matrix of the four Interpersonal Strategies a.pdfcomplete a correlation matrix of the four Interpersonal Strategies a.pdf
complete a correlation matrix of the four Interpersonal Strategies a.pdfFootageetoffe16
 
Compare the differences and uniqueness between Isometric, Oblique, an.pdf
Compare the differences and uniqueness between Isometric, Oblique, an.pdfCompare the differences and uniqueness between Isometric, Oblique, an.pdf
Compare the differences and uniqueness between Isometric, Oblique, an.pdfFootageetoffe16
 

More from Footageetoffe16 (20)

The owner of a small business is planning on expanding his business. .pdf
The owner of a small business is planning on expanding his business. .pdfThe owner of a small business is planning on expanding his business. .pdf
The owner of a small business is planning on expanding his business. .pdf
 
The government safety net creates an adverse selection problem and m.pdf
The government safety net creates an adverse selection problem and m.pdfThe government safety net creates an adverse selection problem and m.pdf
The government safety net creates an adverse selection problem and m.pdf
 
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdf
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdfSyntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdf
Syntrophy often involvesA. hydrogenB.OxygenC. fermentation by.pdf
 
scene from American Samoa Paradise Lost •How does power, both form.pdf
scene from American Samoa Paradise Lost •How does power, both form.pdfscene from American Samoa Paradise Lost •How does power, both form.pdf
scene from American Samoa Paradise Lost •How does power, both form.pdf
 
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdf
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdfQUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdf
QUESTION 25 Chris Korda, an advocate of a certain religion, publishes.pdf
 
Problems2. This is a map for a diploid plantR--------35-------.pdf
Problems2. This is a map for a diploid plantR--------35-------.pdfProblems2. This is a map for a diploid plantR--------35-------.pdf
Problems2. This is a map for a diploid plantR--------35-------.pdf
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdf
 
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdf
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdfPLEASE PLEASE use you own words, do not copy and paste !!!This is .pdf
PLEASE PLEASE use you own words, do not copy and paste !!!This is .pdf
 
List the limitations of the GDP. Which one is most importantSol.pdf
List the limitations of the GDP. Which one is most importantSol.pdfList the limitations of the GDP. Which one is most importantSol.pdf
List the limitations of the GDP. Which one is most importantSol.pdf
 
Information is given about a polynomial f(x) whose coefficients are r.pdf
Information is given about a polynomial f(x) whose coefficients are r.pdfInformation is given about a polynomial f(x) whose coefficients are r.pdf
Information is given about a polynomial f(x) whose coefficients are r.pdf
 
I need to create two binary search trees in Ruby. One using recursio.pdf
I need to create two binary search trees in Ruby. One using recursio.pdfI need to create two binary search trees in Ruby. One using recursio.pdf
I need to create two binary search trees in Ruby. One using recursio.pdf
 
I am studying gut flora and had a few questions.Can you discribe a.pdf
I am studying gut flora and had a few questions.Can you discribe a.pdfI am studying gut flora and had a few questions.Can you discribe a.pdf
I am studying gut flora and had a few questions.Can you discribe a.pdf
 
httpswww.aitp.orgnews98451 Security Administration and Acces.pdf
httpswww.aitp.orgnews98451 Security Administration and Acces.pdfhttpswww.aitp.orgnews98451 Security Administration and Acces.pdf
httpswww.aitp.orgnews98451 Security Administration and Acces.pdf
 
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdf
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdfHwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdf
Hwk due June 7th June 7th Kimmel, Accounting, 6e Help I S ES Exercise.pdf
 
Hint 1 2D array of type Button, all buttons hidden except for one.pdf
Hint 1 2D array of type Button, all buttons hidden except for one.pdfHint 1 2D array of type Button, all buttons hidden except for one.pdf
Hint 1 2D array of type Button, all buttons hidden except for one.pdf
 
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdf
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdfExplain in 3 - 5 paragraphs what different skills and workstyles do .pdf
Explain in 3 - 5 paragraphs what different skills and workstyles do .pdf
 
Describe your supervisors ability and style of communication. Do y.pdf
Describe your supervisors ability and style of communication. Do y.pdfDescribe your supervisors ability and style of communication. Do y.pdf
Describe your supervisors ability and style of communication. Do y.pdf
 
Design a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdfDesign a Windows Desktop application and write the code that will exe.pdf
Design a Windows Desktop application and write the code that will exe.pdf
 
complete a correlation matrix of the four Interpersonal Strategies a.pdf
complete a correlation matrix of the four Interpersonal Strategies a.pdfcomplete a correlation matrix of the four Interpersonal Strategies a.pdf
complete a correlation matrix of the four Interpersonal Strategies a.pdf
 
Compare the differences and uniqueness between Isometric, Oblique, an.pdf
Compare the differences and uniqueness between Isometric, Oblique, an.pdfCompare the differences and uniqueness between Isometric, Oblique, an.pdf
Compare the differences and uniqueness between Isometric, Oblique, an.pdf
 

Recently uploaded

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

1)- Create a specialized version of Insects called FlyingInsects whi.pdf

  • 1. 1)- Create a specialized version of Insects called FlyingInsects which have the ability to fly. 2)- Create a specialized version of Insects called Butterfly which has a state called cocoon and the ability of metamorphosis cocoon is an object of class Cacoon which contains only a toString method which returns the string “Cacoon” (same as class Stinger in Listing C) metamorphosis contains a println which utilizes cacoon (same as protectHive in Listing C) 3)- Refactor the Honeybee and Grasshopper classes into the new hierarchy: honeybees and butterflies can fly while grasshoppers cannot 4)- Modify the BugCollection main program to instantiate a Butterfly object and to call all methods of all Insect subclasses insect.java class bodysection { private String name; public bodysection(String s) { name = s; } public String toString() { return name; } public class insect { private bodysection head; private bodysection thorax; private bodysection abdomen; public insect() { head = new bodysection("head");
  • 2. thorax = new bodysection("thorax"); abdomen = new bodysection("abdomen"); } public void respireLungs() { System.out.println("An insect respires through lungs" + " in its " + thorax); } public void reproduceEggs() { System.out.println("An insect reproduces by laying eggs" + " from its " + abdomen); } } Solution import java.util.Scanner; insect.java class bodysection /** * This class encapsulates the logic and state for a simplified { private String name; public bodysection(String s) { name = s; } public String toString() { return name; } public class insect { private bodysection head; private bodysection thorax; private bodysection abdomen;
  • 3. public insect() { head = new bodysection("head"); thorax = new bodysection("thorax"); abdomen = new bodysection("abdomen"); } public void respireLungs() { System.out.println("An insect respires through lungs" + " in its " + thorax); } public void reproduceEggs() { System.out.println("An insect reproduces by laying eggs" + " from its " + abdomen); } }