Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inheritance Short Answer Question siger une nierarchy or CSCS SERWII Ura d ordy tice that an Owl is-a Bird, a Snowyowl is-a Owl, and an

Inheritance Short Answer Question image text in transcribed
image text in transcribed
siger une nierarchy or CSCS SERWII Ura d ordy tice that an Owl is-a Bird, a Snowyowl is-a Owl, and an Blowl is-a Owl. The class Bird is ecified as shown in the following implementation. Each Bird has a name and a noise that are specified when s constructed. public class Bird { private String name, noise; /**Constructor for objects of class Bird */ public Bird (String birdName, String birdNoise) name - birdName; noise - birdNoise; public String getName() return name; public String getNoise () return noise; public String get Food() return "Let's eat"; Owl is a Bird whose noise is "hoot". The food it eats depends on the type of Owl, which means that tFood cannot be implemented in the Owl class. Here is the implementation for the Owl class. { public class Owl extends Bird //Constructor public owl (String owlName) super (owlName, "hoot); a. A Snowyowl is an Owl whose name is always "Snowy owl". A Snowyowl will randomly eat a hare, a lemming, or a small bird (depending on what's available), where each type of food is equally likely. The Snowyowl class should use a random number to determine which food the Snowyowl will eat. Assuming that the owl class has been correctly defined, and given the class hierarchy shown previously, write a complete declaration of the class Snowyowl, including implementation of its constructor and method(s). b. Consider the following partial declaration of class BirdSanctuary, public class BirdSanctuary /**The list of birds */ private Bird'l birdList; /**Precondition: Each Bird in birdList has a getFood method implemented for it. * Postcondition: For each Bird in the birdList array, its name followed by the result of a call to its getFood method has been printed, one line per Bird. public void alleat () { /*to be implemented in this part */ } //The constructor and other methods are not shown. Write the Birdsanctuary method alleat. For each Bird in Birdsanctuatry, allat prints a line with the name of the Bird followed by the result of a call to its get Food method, one line per Bird. Complete method alleat below. /**Precondition: Each Bird in birdList has a getFood method implemented for it. * Postcondition: For each Bird in the birdList array, its name followed by the result of a call to its get Food method has been printed, one line per Bird. public void alleat()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions