Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem #1 (10 marks) a) Design and implement an abstract class called Animal that contains one instance variable of type String that stores the name

Problem #1 (10 marks) a) Design and implement an abstract class called Animal that contains one instance variable of type String that stores the name of an animal (name) and appropriate accessor and mutator methods. Include a constructor that stores the name and toString() method to prints the animals name. The class also has two abstract methods, sound( ) and movement( ). The return type of the methods is String. b) Create 3 classes that inherit from Animal: Owl, Donkey, and Frog. Add an instance variable, age (int) to each of these classes. Develop a constructor that invokes the constructor of its parent class with a name and stores an age in each class. Create appropriate accessor and mutator methods for the age. Implement sound and movement methods in each class that return proper information: Owls hoot (sound) and fly (movement); donkeys hee-haw and walk; frogs ribbit and jump. Override toString() methods that returns a string of all information (including sound and movement information) in each class. c) Create an application/driver that thoroughly tests all methods of the 3 classes described in b). Problem #2 (10 marks) a) Problem #2 is similar to Problem #1. But the Animal class is a regular class, not an abstract class. b) Add (or modify from Problem #1) the instance variable, name in the Animal class that is now accessible by each child class (Owl, Donkey, and Frog), i.e. we could have a red tailed hawk. The Animal class does not have sound() and movement() methods anymore. c) Add a get and set methods for the instance variable, name in the Animal class accessible by each child class. d) Owls have a wingspan: add that instance variable and a get and set method for it. e) Donkeys have a weight: add that instance variable and a get and set method for it. f) Frogs have a length: add that instance variable and a get and set method for it. g) Create an array of Animals containing at least 3 animals of each type (owls, donkeys and frogs). Using polymorphism, display the details of each animal in the array. (youll need to modify the toString methods from Problem #1) h) Use a cast to access the animals in the array to do sets and gets of wingspan, weight, and length. Show that the code works by producing suitable outputs. Problem #3 a) Create an interface called Sound that contains 1 method called getSound. b) Create an interface called Movement that contains 1 method called getMovement. c) Modify the 4 classes from Problem #2 to implement the Sound and Movement interfaces. Owls hoot (sound) and fly (movement); donkeys hee-haw and walk; frogs ribbit and jump. d) The classes described in c) should also implement the Comparable interface. (that is, they implement 3 interfaces) Owls are compared by wing span, donkeys by weight, and frogs by how long they are. e) Create an application that thoroughly tests the classes described above. Your application should demonstrate that all 3 interfaces have been successfully implemented. (Note the compareTo method must be tested for each type of animal). f) Lastly create a Sound array with at least 2 animals of each type (hawks, elephants, and snakes) and verify the interface works correctly using polymorphism to access the getSound method.

please use some space after the solution of each question. Please givethose answer as early as possible. Thanks in advance.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions