1. First, create an interface named Pet in a file called Pet.java. This interface shoul have three methods: getName().getType(), and getSound(), all of which return String and should not take anything as arguments. 2. Second, rewrite the Cat class so that it implements the Pet interface. 3. Third, create another class (of your choice) that implements the Pet interface. Make one of the methods interesting in some way (i.e. instead of randomly choosing between two sounds... choose between 3 sounds, or maybe change th name randomly. Whatever strikes your fancy.) 4. Then, modify Main so that you have an ArrayList of Pets. a. If you don't remember how to create an ArrayList... this code will do it: ArrayList pets. = new ArrayList (); pets.add(new Cat ("Bootes")); b. Place in there a mix of Cat and "other" (whatever class you made in step Because we declare the ArrayList to be of type Pet, we can fully leverage polymorphism that is available with the interface. c. Use a for loop to iterate through this array and generate some output to show that you have several Pets of different types. Sample output: This one is a Cat. amed Bootes
1. First, create an interface named Pet in a file called Pet.java. This interface shoul have three methods: getName().getType(), and getSound(), all of which return String and should not take anything as arguments. 2. Second, rewrite the Cat class so that it implements the Pet interface. 3. Third, create another class (of your choice) that implements the Pet interface. Make one of the methods interesting in some way (i.e. instead of randomly choosing between two sounds... choose between 3 sounds, or maybe change th name randomly. Whatever strikes your fancy.) 4. Then, modify Main so that you have an ArrayList of Pets. a. If you don't remember how to create an ArrayList... this code will do it: ArrayList pets. = new ArrayList (); pets.add(new Cat ("Bootes")); b. Place in there a mix of Cat and "other" (whatever class you made in step Because we declare the ArrayList to be of type Pet, we can fully leverage polymorphism that is available with the interface. c. Use a for loop to iterate through this array and generate some output to show that you have several Pets of different types. Sample output: This one is a Cat. amed Bootes
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
give me a example of this please i am confused
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education