Knowee
Questions
Features
Study Tools

You are creating a game where kids play as different animals in a magical forest. Each animal has unique characteristics and abilities. The game features two types of animals: "Lion" and "Eagle." Both animals inherit from a base class called "Animal," which contains common attributes and behaviors.Requirements:Implement a base class Animal with the following attributes:name (string): stores the name of the animal.age (int): stores the age of the animal.happinessLevel (int): stores the current happiness level of the animal.Implement a pure virtual function void specialAbility() in the Animal class, which will be overridden by derived classes.Implement derived classes Lion and Eagle from the Animal class.The Lion class should have an additional attribute:maneColor (string): stores the color of the lion's mane.Override the specialAbility() function to output a message indicating the lion's special ability. If the lion's age is less than 3, it should playfully roars; if the age is between 3 and 6, it should roar loudly; if the age is greater than 6 and happiness level is high (greater than 5), it should roar fiercely and proudly; otherwise, it should just yawn.The Eagle class should have an additional attribute:wingSpan (int): stores the wingspan of the eagle in centimeters.Override the specialAbility() function to output a message indicating the eagle's special ability. If the eagle's wing span is less than 100, it should fly low; if the wing span is between 100 and 200, it should soar high; if the wing span is greater than 200 and happiness level is high ((greater than 5), it should perform aerial acrobatics; otherwise, it should just glide.Sample Input:LionSimba2  // age7  //happinessLevelGolden   //maneColorEagleEddy48  //happinessLevel180   //wingSpanSample Output:Simba playfully roars!Eddy soars high!

Question

You are creating a game where kids play as different animals in a magical forest. Each animal has unique characteristics and abilities. The game features two types of animals: "Lion" and "Eagle." Both animals inherit from a base class called "Animal," which contains common attributes and behaviors.Requirements:Implement a base class Animal with the following attributes:name (string): stores the name of the animal.age (int): stores the age of the animal.happinessLevel (int): stores the current happiness level of the animal.Implement a pure virtual function void specialAbility() in the Animal class, which will be overridden by derived classes.Implement derived classes Lion and Eagle from the Animal class.The Lion class should have an additional attribute:maneColor (string): stores the color of the lion's mane.Override the specialAbility() function to output a message indicating the lion's special ability. If the lion's age is less than 3, it should playfully roars; if the age is between 3 and 6, it should roar loudly; if the age is greater than 6 and happiness level is high (greater than 5), it should roar fiercely and proudly; otherwise, it should just yawn.The Eagle class should have an additional attribute:wingSpan (int): stores the wingspan of the eagle in centimeters.Override the specialAbility() function to output a message indicating the eagle's special ability. If the eagle's wing span is less than 100, it should fly low; if the wing span is between 100 and 200, it should soar high; if the wing span is greater than 200 and happiness level is high ((greater than 5), it should perform aerial acrobatics; otherwise, it should just glide.Sample Input:LionSimba2  // age7  //happinessLevelGolden   //maneColorEagleEddy48  //happinessLevel180   //wingSpanSample Output:Simba playfully roars!Eddy soars high!

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python implementation of the game:

class Animal:
    def __init__(self, name, age, happinessLevel):
        self.name = name
        self.age = age
        self.happinessLevel = happinessLevel

    def specialAbility(self):
        pass

class Lion(Animal):
    def __init__(self, name, age, happinessLevel, maneColor):
        super().__init__(name, age, happinessLevel)
        self.maneColor = maneColor

    def specialAbility(self):
        if self.age < 3:
            return f"{self.name} playfully roars!"
        elif 3 <= self.age <= 6:
            return f"{self.name} roars loudly!"
        elif self.age > 6 and self.happinessLevel > 5:
            return f"{self.name} roars fiercely and proudly!"
        else:
            return f"{self.name} just yawns."

class Eagle(Animal):
    def __init__(self, name, age, happinessLevel, wingSpan):
        super().__init__(name, age, happinessLevel)
        self.wingSpan = wingSpan

    def specialAbility(self):
        if self.wingSpan < 100:
            return f"{self.name} flies low!"
        elif 100 <= self.wingSpan <= 200:
            return f"{self.name} soars high!"
        elif self.wingSpan > 200 and self.happinessLevel > 5:
            return f"{self.name} performs aerial acrobatics!"
        else:
            return f"{self.name} just glides."

# Sample Input
lion = Lion("Simba", 2, 7, "Golden")
eagle = Eagle("Eddy", 4, 8, 180)

# Sample Output
print(lion.specialAbility())
print(eagle.specialAbility())

This code first defines a base class Animal with the common attributes and a specialAbility method. Then it defines two derived classes Lion and Eagle that inherit from Animal and override the specialAbility method. The specialAbility method in each derived class checks the animal's attributes to determine the appropriate message to return. The sample input and output demonstrate how to create instances of these classes and call their methods.

This problem has been solved

Similar Questions

Develop a Java program that demonstrates inheritance between two classes:the superclass Animal and its subclass Dog.

Create a class called Animal with a method sound() that displays a generic sound. Then, create a subclass called Dog that inherits from Animal and overrides the sound() method to display "Woof". Create another subclass called Cat that inherits from Animal and overrides the sound() method to display "Meow". Finally, create a subclass called Cow that inherits from Animal and overrides the sound() method to display "Moo". In the main method, create objects of Dog, Cat, and Cow classes and call the sound() method for each object

Example questions(10 marks)• Explain the following concepts and illustratehow you can use them with examples.i. Encapsulationii. Information hidingiii. Private helperiv. Polymorphismv. Default constructorExample questions(15 marks)Suppose that a Mammal class written in Java is already available which youcan use (i.e., you are not asked to write this class). This class has instancevariables, constructors and methods as described below:1. instance variables that represent a mammal’s name as a String and themammal’s age as an integer2. a default constructor3. a constructor which is given a mammal’s name as a String and themammal’s age as an integer4. a method set (…) for setting the name and age of a mammal5. a method named printDetails() that prints out the name and the age ofthe mammal6. an equals(…) method which compares the parameter of mammal class tothe current object and returns true if two mammals have the same nameand same ageExample questions• Give Java code for a client program which uses the Mammalclass to do the following. It will create a Mammal object usingthe default constructor. It will then get the name and age of amammal from the user and set the Mammal object to theinput values. The program will then get the name and age of asecond mammal from the user and create the secondmammal object using the non-default constructor. It will thendetermine whether or not the two mammals are the sameand display this information. Finally, the program will print outthe details of the two mammals.

Determine other features that could be used to classify the animals in a different way.

Problem StatementProgram to implement the run time polymorphism.Input Format:Single line of input contain a dog or cat.Output Format:Single line of output contain input animal speaking sound.Sample Input:Enter the type of animal (Dog or Cat): catSample Output:The cat says: Meow!

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.