Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write classes and interfaces to represent the following: Adoptable Amphibian Ani

ID: 3678734 • Letter: W

Question

Write classes and interfaces to represent the following:

Adoptable

Amphibian

Animal

Bat

Dog

Fish

Frog

Flyable

Goldfish

Mammal

WaterLiveable

Whale

You need to decide on the structure. Consider:

Which should be an abstract class?

Which should be an interface?

How should the classes be related through inheritance?

In what classes should methods be placed?

What methods should be overridden?

Some additional details/requirements:

All animals have a name.

All classes have a toString method that returns the animal's name.

All animals have a method "isWarmBlooded" that returns a boolean.

Animals that can be adopted as pets have a method "getHomecareInstructions" that return a description of how to care for the animal.

Animals that can live underwater have a method "canLiveOnLand" that returns a boolean of whether the animal can also live on land.

Animals that can fly have a method "getFlightSpeed" that returns the average miles per hour that the animal can fly.

This assignment isn't necessarily difficult from a programming perspective. What you should spend time on instead is carefully considering the design of you classes and how they should be related through inheritance or interfaces. To get full credit:

Your class hierarchy should make sense. (You can assume common knowledge or "googleable" facts about animals- you won't be graded on your biology knowledge!)

Place common code as high up in the hierarchy as possible.

Declare classes that should not be instantiated as abstract.

In abstract classes, methods that must be implemented by all subclasses should be declared abstract.

Remember that classes can only have one parent but can implement multiple interfaces.

Test file should look like this

Explanation / Answer

This is a part of the code given, the remaining structure follows the same.


#include <string>
#include <iostream>

class Flyable
{
   public:
       virtual public bool isFlyable() = 0;
       virtual public int getFlightSpeed() = 0;
};

class WaterLiveable
{
   public:
       virtual public bool canLiveOnLand() = 0;
};

class Mammal
{
   public:
       virtual public void property_Renamed() = 0;
};

class Adoptable : public Flyable, public Mammal
{
   public:
       virtual public bool isAdoptable() = 0;
       virtual public std::wstring getHomeCareInstructions() = 0;
};

class Animal
{
   public:
       std::wstring name;

       virtual bool isWarmBlooded() = 0;
};

class Bat : public Animal, public Adoptable
{
   public:
       Bat(const std::wstring &name)
       {
               Animal::name = name;
       }
       virtual bool isFlyable()
       {
               return true;
       }

       virtual int getFlightSpeed()
       {
               return 30;
       }

       virtual bool isWarmBlooded() override
       {
               return false;
       }
       virtual std::wstring getHomeCareInstructions()
       {
           return L"";
       }
       virtual bool isAdoptable()
       {
               return false;
       }
       virtual void property_Renamed()
       {
               std::wcout << std::wstring(L"BATS SEE AT NIGHT") << std::endl;
       }
       virtual std::wstring toString() override
       {
               return name;
       }
};

class Dog : public Animal, public Adoptable
{
   public:
       Dog(const std::wstring &name)
       {
               Animal::name = name;
       }
       virtual bool isFlyable()
       {
               return false;
       }
       virtual int getFlightSpeed()
       {
               return 0;
       }

       virtual bool isWarmBlooded() override
       {
               return true;
       }
       virtual std::wstring getHomeCareInstructions()
       {
           return L"DOGS NEED BATH AND FOOD AND MEDCINE";
       }
       virtual bool isAdoptable()
       {
               return true;
       }
       virtual void property_Renamed()
       {
               std::wcout << std::wstring(L"DOGS ARE GOOD") << std::endl;
       }
       virtual std::wstring toString() override
       {
               return name;
       }
};

class AnimalKingdomTester
{
       static void main(std::wstring args[])
       {
               Bat *b = new Bat(L"BAT1");
               if (b->isAdoptable())
               {
                   std::wcout << b->toString() << std::wstring(L" is Adoptable and home caring conditions are : ") << b->getHomeCareInstructions() << std::endl;
               }
               if (b->isFlyable())
               {
                   std::wcout << b->toString() << std::wstring(L" has Flight Speed : ") << b->getFlightSpeed() << std::endl;
               }

               Dog *d = new Dog(L"XXX");
               if (d->isAdoptable())
               {
                   std::wcout << d->toString() << std::wstring(L" is Adoptable and home caring conditions are : ") << d->getHomeCareInstructions() << std::endl;
               }
               if (d->isFlyable())
               {
                   std::wcout << d->toString() << std::wstring(L" has Flight Speed : ") << d->getFlightSpeed() << std::endl;
               }
       }
};

JAVA CODE

interface Flyable
   {
       public boolean isFlyable();
       public int getFlightSpeed();
   }
  
interface WaterLiveable
   {
       public boolean canLiveOnLand();
   }
      
interface Mammal
   {
       public void property();
   }
  
interface Adoptable extends Flyable, Mammal
   {
       public boolean isAdoptable();
       public String getHomeCareInstructions();
   }
  
abstract class Animal
   {
       String name;
      
       public abstract boolean isWarmBlooded();
   }
  
class Bat extends Animal implements Adoptable
   {
       Bat(String name)
           {
               super.name = name;
           }
       public boolean isFlyable()
           {
               return true;
           }
          
       public int getFlightSpeed()
           {
               return 30;
           }
          
       public boolean isWarmBlooded()
           {
               return false;
           }
       public String getHomeCareInstructions(){return "";}
       public boolean isAdoptable()
           {
               return false;
           }
       public void property()
           {
               System.out.println("BATS SEE AT NIGHT");
           }
       public String toString()
           {
               return name;
           }
   }
  
class Dog extends Animal implements Adoptable
   {
       Dog(String name)
           {
               super.name = name;
           }
       public boolean isFlyable()
           {
               return false;
           }
       public int getFlightSpeed()
           {
               return 0;
           }
          
       public boolean isWarmBlooded()
           {
               return true;
           }
       public String getHomeCareInstructions(){return "DOGS NEED BATH AND FOOD AND MEDCINE";}
       public boolean isAdoptable()
           {
               return true;
           }
       public void property()
           {
               System.out.println("DOGS ARE GOOD");
           }
       public String toString()
           {
               return name;
           }
   }  
  
public class AnimalKingdomTester
   {
       public static void main(String args[])
           {
               Bat b = new Bat("BAT1");
               if(b.isAdoptable())
                   System.out.println(b.toString() + " is Adoptable and home caring conditions are : " + b.getHomeCareInstructions());
               if(b.isFlyable())
                   System.out.println(b.toString() + " has Flight Speed : " + b.getFlightSpeed());

               Dog d = new Dog("XXX");
               if(d.isAdoptable())
                   System.out.println(d.toString() + " is Adoptable and home caring conditions are : " + d.getHomeCareInstructions());
               if(d.isFlyable())
                   System.out.println(d.toString() + " has Flight Speed : " + d.getFlightSpeed());                  
           }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote