SlideShare a Scribd company logo
Use the following code for the tasks:
public class Animal {
private String name;
public Animal ( String name ) {
this.name = name;
}
public String getName ( ) { return name; }
public String speak ( ) {
return name;
}
}
public class Cat extends Animal {
public Cat ( String name ) {
super ( name );
}
public String speak ( ) {
return "Rawr!";
}
}
public class Dog extends Animal {
public Dog ( String name ) {
super ( name );
}
public String speak ( ) {
return "Woof!";
}
}
import java.util.ArrayList;
public class Speak {
public static void main ( String [] args ) {
// Instantiate an object and make it speak.
Animal a = ?;
System.out.println ( a.speak() );
}
}
Task #1:
Examine the contents of the Speak.java class. This file doesn't really contain much. But create at
least 1 animal of either a Dog or Cat type. Then print out the results of the animal speaking. You
should see a "Woof!" or "Rawr!" outputted to the console.
But then modify the Dog or Cat class (whichever you created) such that the speak method returns
the name of the animal, the type of the animal, and then the noise the animal makes. Such that
the output looks something like this:
Barkley (dog): Woof!
OR
Miss Kitty (cat): Meow!
I recommend that you use the getName method to get the name of the animal. Test the output so
that it produces the expected results. The modify the other subclass for animal such that it act
similarly.
Task #2:
Now create your own subclass for animal. Use the Cat or Dog as a guide on how to create the
new subclass. The subclass must be an animal whose first letter of the type is the same first letter
as your name. For instance, if your name is "Zendaya" then you may want to make and animal
subtype "Zebra". Make sure that you make a speak method for the animal such that it makes the
animal's common noise.
Be sure to test the animal out in the same way that you tested for Task #1.
Zebulon (zebra): Yip!
Task #3:
But wait a second. Typical housecats don't really roar (rawr!). That's something that lions do. Make
a copy of the Cat class, naming the copy "Lion" instead. It should do everything a Cat does except
it should be a lion. So really the Lion class should extend the Cat class.
Then go back and change the Cat class so that it says "Meow!" instead of roaring. Test the code
for Cat and Lion in your Speak class to ensure that they both work.
Task #4:
Once you have complete task #3. Create a similar change in the Animal hierarchy for Dog. This
time make a new Wolf class that extends Dog. This new class should do everything a Dog does.
Except when it speaks it should howl: "Awoooooooo!". You can decide how many o's this should
contain. Test the code for Dog and Wolf in your Speak class to ensure that they both work.
Task #5:
We should have a hierarchy of animals that looks like the image at the bottom of the page (except
the Zebra will probably be different). So our last task is to make an ArrayList of all these different
types of animals. Declare and instantiate the ArrayList so that it is able to contain Animals. Then
instantiate 7 different Animal subclasses (do not instantiate an Animal) putting each of the animals
in the ArrayList.
Once the ArrayList if filled with Animals, then create one of the special for-each loops that will
iterate through all of the animals in the list. Print out the result of each animal speaking such that
you end up with output the looks similar to the output described in the introduction for the lab.
Task #6:
Lastly, but most importantly, take a screenshot of the resulting output when your run the Speak
program. Make sure your console panel is large enough to hold all the lines of output. Then submit
the screenshot and the important files that you created/modified in this lab:
Speak.java, Cat.java, Lion.java, Wolf.java, <your animal>.java
The output should end up looking something like this. Of course, your solution may appear
different depending upon what is coded as sounds from your animals. What sound does a koala
make?
$ java Speak
Barkley (dog): Woof!
Miss Kitty (cat): Meow!
Leo (lion): Rawr!!
Lobo (wolf): Awoooooooo!!
Kody (koala): 0w0

More Related Content

Similar to Use the following code for the tasks public class Animal .pdf

Fire in the type hole
Fire in the type holeFire in the type hole
Fire in the type hole
ihji
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineering
IRAH34
 
1 CS110 - Introduction to Computers and Applications .docx
1  CS110 - Introduction to Computers and Applications .docx1  CS110 - Introduction to Computers and Applications .docx
1 CS110 - Introduction to Computers and Applications .docx
honey725342
 
Ceylon idioms by Gavin King
Ceylon idioms by Gavin KingCeylon idioms by Gavin King
Ceylon idioms by Gavin King
UnFroMage
 
Class
ClassClass
Class
mussawir20
 
Cite References.Classification in Discriminant Analysis Discussi.docx
Cite References.Classification in Discriminant Analysis Discussi.docxCite References.Classification in Discriminant Analysis Discussi.docx
Cite References.Classification in Discriminant Analysis Discussi.docx
clarebernice
 
Polymorphism.ppt
Polymorphism.pptPolymorphism.ppt
Polymorphism.ppt
EmanAsem4
 
Using C+t Create a class name Dog with a string field for the Dog's na.pdf
Using C+t Create a class name Dog with a string field for the Dog's na.pdfUsing C+t Create a class name Dog with a string field for the Dog's na.pdf
Using C+t Create a class name Dog with a string field for the Dog's na.pdf
DaviddA7Paynez
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPS
rithustutorials
 
Prototypes
PrototypesPrototypes
Prototypes
alexisabril
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
Java interfaces
Java interfacesJava interfaces
Java interfaces
Stavros Antifakos
 
Learning puppet chapter 2
Learning puppet chapter 2Learning puppet chapter 2
Learning puppet chapter 2
Vishal Biyani
 
Unit 1.3 Introduction to Programming (Part 3)
Unit 1.3 Introduction to Programming (Part 3)Unit 1.3 Introduction to Programming (Part 3)
Unit 1.3 Introduction to Programming (Part 3)
Intan Jameel
 
from media import #useful functions to manipulate sounds#Chan.docx
from media import #useful functions to manipulate sounds#Chan.docxfrom media import #useful functions to manipulate sounds#Chan.docx
from media import #useful functions to manipulate sounds#Chan.docx
hanneloremccaffery
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
Chiyoung Song
 
EESTEC Android Workshops - 101 Java, OOP and Introduction to Android
EESTEC Android Workshops - 101 Java, OOP and Introduction to AndroidEESTEC Android Workshops - 101 Java, OOP and Introduction to Android
EESTEC Android Workshops - 101 Java, OOP and Introduction to Android
Antonis Kalipetis
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Duckademy IT courses
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx
Thắng It
 

Similar to Use the following code for the tasks public class Animal .pdf (20)

Fire in the type hole
Fire in the type holeFire in the type hole
Fire in the type hole
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineering
 
1 CS110 - Introduction to Computers and Applications .docx
1  CS110 - Introduction to Computers and Applications .docx1  CS110 - Introduction to Computers and Applications .docx
1 CS110 - Introduction to Computers and Applications .docx
 
Ceylon idioms by Gavin King
Ceylon idioms by Gavin KingCeylon idioms by Gavin King
Ceylon idioms by Gavin King
 
Class
ClassClass
Class
 
Cite References.Classification in Discriminant Analysis Discussi.docx
Cite References.Classification in Discriminant Analysis Discussi.docxCite References.Classification in Discriminant Analysis Discussi.docx
Cite References.Classification in Discriminant Analysis Discussi.docx
 
Polymorphism.ppt
Polymorphism.pptPolymorphism.ppt
Polymorphism.ppt
 
Using C+t Create a class name Dog with a string field for the Dog's na.pdf
Using C+t Create a class name Dog with a string field for the Dog's na.pdfUsing C+t Create a class name Dog with a string field for the Dog's na.pdf
Using C+t Create a class name Dog with a string field for the Dog's na.pdf
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPS
 
Prototypes
PrototypesPrototypes
Prototypes
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Learning puppet chapter 2
Learning puppet chapter 2Learning puppet chapter 2
Learning puppet chapter 2
 
Unit 1.3 Introduction to Programming (Part 3)
Unit 1.3 Introduction to Programming (Part 3)Unit 1.3 Introduction to Programming (Part 3)
Unit 1.3 Introduction to Programming (Part 3)
 
from media import #useful functions to manipulate sounds#Chan.docx
from media import #useful functions to manipulate sounds#Chan.docxfrom media import #useful functions to manipulate sounds#Chan.docx
from media import #useful functions to manipulate sounds#Chan.docx
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
EESTEC Android Workshops - 101 Java, OOP and Introduction to Android
EESTEC Android Workshops - 101 Java, OOP and Introduction to AndroidEESTEC Android Workshops - 101 Java, OOP and Introduction to Android
EESTEC Android Workshops - 101 Java, OOP and Introduction to Android
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx
 

More from adityknits

Using best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdfUsing best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdf
adityknits
 
Using Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdfUsing Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdf
adityknits
 
User Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdfUser Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdf
adityknits
 
Using a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdfUsing a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdf
adityknits
 
UserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdfUserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdf
adityknits
 
used below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdfused below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdf
adityknits
 
Use to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdfUse to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdf
adityknits
 
Use this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdfUse this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdf
adityknits
 
Use the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdfUse the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdf
adityknits
 
Use the spreadsheet extract to answer the questions Requir.pdf
Use the spreadsheet extract to answer the questions   Requir.pdfUse the spreadsheet extract to answer the questions   Requir.pdf
Use the spreadsheet extract to answer the questions Requir.pdf
adityknits
 
Use the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdfUse the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdf
adityknits
 
Use the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdfUse the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdf
adityknits
 
Use the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdfUse the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdf
adityknits
 
Use the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdfUse the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdf
adityknits
 
Use the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdfUse the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdf
adityknits
 
Use the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdfUse the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdf
adityknits
 
Use the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdfUse the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdf
adityknits
 
Use the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdfUse the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdf
adityknits
 
Use the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdfUse the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdf
adityknits
 
Use the following scenario to respond to items 10 and 11 T.pdf
Use the following scenario to respond to items 10 and 11  T.pdfUse the following scenario to respond to items 10 and 11  T.pdf
Use the following scenario to respond to items 10 and 11 T.pdf
adityknits
 

More from adityknits (20)

Using best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdfUsing best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdf
 
Using Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdfUsing Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdf
 
User Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdfUser Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdf
 
Using a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdfUsing a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdf
 
UserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdfUserInputHandlerjava package midterm2023 import javautil.pdf
UserInputHandlerjava package midterm2023 import javautil.pdf
 
used below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdfused below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdf
 
Use to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdfUse to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdf
 
Use this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdfUse this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdf
 
Use the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdfUse the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdf
 
Use the spreadsheet extract to answer the questions Requir.pdf
Use the spreadsheet extract to answer the questions   Requir.pdfUse the spreadsheet extract to answer the questions   Requir.pdf
Use the spreadsheet extract to answer the questions Requir.pdf
 
Use the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdfUse the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdf
 
Use the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdfUse the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdf
 
Use the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdfUse the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdf
 
Use the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdfUse the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdf
 
Use the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdfUse the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdf
 
Use the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdfUse the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdf
 
Use the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdfUse the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdf
 
Use the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdfUse the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdf
 
Use the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdfUse the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdf
 
Use the following scenario to respond to items 10 and 11 T.pdf
Use the following scenario to respond to items 10 and 11  T.pdfUse the following scenario to respond to items 10 and 11  T.pdf
Use the following scenario to respond to items 10 and 11 T.pdf
 

Recently uploaded

How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 

Recently uploaded (20)

How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 

Use the following code for the tasks public class Animal .pdf

  • 1. Use the following code for the tasks: public class Animal { private String name; public Animal ( String name ) { this.name = name; } public String getName ( ) { return name; } public String speak ( ) { return name; } } public class Cat extends Animal { public Cat ( String name ) { super ( name ); } public String speak ( ) { return "Rawr!"; } } public class Dog extends Animal { public Dog ( String name ) { super ( name ); } public String speak ( ) { return "Woof!"; } } import java.util.ArrayList; public class Speak { public static void main ( String [] args ) { // Instantiate an object and make it speak. Animal a = ?; System.out.println ( a.speak() ); } } Task #1: Examine the contents of the Speak.java class. This file doesn't really contain much. But create at least 1 animal of either a Dog or Cat type. Then print out the results of the animal speaking. You should see a "Woof!" or "Rawr!" outputted to the console. But then modify the Dog or Cat class (whichever you created) such that the speak method returns the name of the animal, the type of the animal, and then the noise the animal makes. Such that the output looks something like this:
  • 2. Barkley (dog): Woof! OR Miss Kitty (cat): Meow! I recommend that you use the getName method to get the name of the animal. Test the output so that it produces the expected results. The modify the other subclass for animal such that it act similarly. Task #2: Now create your own subclass for animal. Use the Cat or Dog as a guide on how to create the new subclass. The subclass must be an animal whose first letter of the type is the same first letter as your name. For instance, if your name is "Zendaya" then you may want to make and animal subtype "Zebra". Make sure that you make a speak method for the animal such that it makes the animal's common noise. Be sure to test the animal out in the same way that you tested for Task #1. Zebulon (zebra): Yip! Task #3: But wait a second. Typical housecats don't really roar (rawr!). That's something that lions do. Make a copy of the Cat class, naming the copy "Lion" instead. It should do everything a Cat does except it should be a lion. So really the Lion class should extend the Cat class. Then go back and change the Cat class so that it says "Meow!" instead of roaring. Test the code for Cat and Lion in your Speak class to ensure that they both work. Task #4: Once you have complete task #3. Create a similar change in the Animal hierarchy for Dog. This time make a new Wolf class that extends Dog. This new class should do everything a Dog does. Except when it speaks it should howl: "Awoooooooo!". You can decide how many o's this should contain. Test the code for Dog and Wolf in your Speak class to ensure that they both work. Task #5: We should have a hierarchy of animals that looks like the image at the bottom of the page (except the Zebra will probably be different). So our last task is to make an ArrayList of all these different types of animals. Declare and instantiate the ArrayList so that it is able to contain Animals. Then instantiate 7 different Animal subclasses (do not instantiate an Animal) putting each of the animals in the ArrayList. Once the ArrayList if filled with Animals, then create one of the special for-each loops that will iterate through all of the animals in the list. Print out the result of each animal speaking such that you end up with output the looks similar to the output described in the introduction for the lab. Task #6: Lastly, but most importantly, take a screenshot of the resulting output when your run the Speak program. Make sure your console panel is large enough to hold all the lines of output. Then submit the screenshot and the important files that you created/modified in this lab: Speak.java, Cat.java, Lion.java, Wolf.java, <your animal>.java The output should end up looking something like this. Of course, your solution may appear different depending upon what is coded as sounds from your animals. What sound does a koala make?
  • 3. $ java Speak Barkley (dog): Woof! Miss Kitty (cat): Meow! Leo (lion): Rawr!! Lobo (wolf): Awoooooooo!! Kody (koala): 0w0