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

In java language Write classes and interfaces to represent the following: Adopta

ID: 3679435 • Letter: I

Question

In java language

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.

I have included a test file you can use to test your code. Note that this file might not contain all possibilities you want to test! You can edit this file to add more tests if necessary.

Explanation / Answer

First I will explain the class heiarchy and interfaces which I have created

There are three interfaces

Adoptable with method "getHomecareInstructions"  for animals that can be adopted as pets .

Flyable with a method "getFlightSpeed" that returns the average miles per hour that the animal can fly.

WaterLiveable with a method "canLiveOnLand" for animals which live underwater

I have created a abstract class Animal which has the name property for all animals and toString method to return the name of all the animals

Then I have created three more abstract classes Mammal,Fish,Amphibian which extend the class Animal and implement the method isWarmBlooded which is common for all animals belonging to any of these categories.

All other classes are concrete classes and extend above three abstract classes and implement the above mentioned interfaces according to the requirement

Adoptable.java

public interface Adoptable {

   public String getHomeCareInstructions();

}

Flyable.java

public interface Flyable {

   public double getFlightSpeed();

}

WaterLiveable.java

public interface WaterLiveable {

   public boolean canLiveOnLand();

}

Animal.java

public abstract class Animal {

   private String name;   

   public Animal(String animalName)

   {

       name=animalName;

   }   

   public String toString()

   {

       return name;

   }

public abstract boolean isWarmBlooded();

}

Mammal.java

public abstract class Mammal extends Animal {

   public Mammal(String animalName) {

       super(animalName);

   }

   public boolean isWarmBlooded()

   {

       return true;

   }

}

Fish.java

public abstract class Fish extends Animal {

   public Fish(String animalName) {

       super(animalName);

   }

   public boolean isWarmBlooded()

   {

       return false;

   }

}

Amphibian.java

public abstract class Amphibian extends Animal {

   public Amphibian(String animalName) {

       super(animalName);

   }

   public boolean isWarmBlooded()

   {

       return false;

   }

}

Bat.java

public class Bat extends Mammal implements Flyable {

private double speed;

   public Bat(String animalName,double s) {

       super(animalName);

speed=s;

   }

   public double getFlightSpeed() {

       return speed;

   }

}

Dog.java

public class Dog extends Mammal implements Adoptable {

   public Dog(String animalName) {

       super(animalName);

   }

   public String getHomeCareInstructions() {

       return "Feed the dog properly and keep him away from loud music..";

   }

}

Frog.java

public class Frog extends Amphibian implements WaterLiveable {

   public Frog(String animalName) {

       super(animalName);

   }

   public boolean canLiveOnLand() {

       return true;

   }

}

Goldfish.java

public class Goldfish extends Fish implements Adoptable,WaterLiveable {

   public Goldfish(String animalName) {

       super(animalName);

   }

   public boolean canLiveOnLand() {

       return false;

   }

   public String getHomeCareInstructions() {

       return "Keep the fish in water if you wan't them to be alive and feed them properly" ;

   }

}

Whale.java

public class Whale extends Mammal implements WaterLiveable {

   public Whale(String animalName) {

       super(animalName);

   }

   public boolean canLiveOnLand() {

       return false;

   }

}

output:

Rover is a Dog which is warm blooded.

   Feed the dog properly and keep him away from loud music..

Beluga is a Whale which is warm blooded.

   Beluga can live in the water but cannot live on land.

Dracky is a Bat which is warm blooded.

   Flies up to 15.0 mph!

Nemo is a Goldfish which is not warm blooded.

   Keep the fish in water if you wan't them to be alive and feed them properly

   Nemo can live in the water but cannot live on land.

Prince is a Frog which is not warm blooded.

   Prince can live in the water and can also live on land.

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