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

In this project we will create a base class to represent animals of various kind

ID: 3693254 • Letter: I

Question

In this project we will create a base class to represent animals of various kinds. Class Animal

Then we will create derived classes to represent specific kinds of animals. Dog Cat Bird

Every animal has Kind of animal (Dog, Cat, Bird) Name Owner's name Date of Birth

Create a class, Animal, to hold information common to all animals. Will be a base class for derived classes representing specific kinds of animals.

Define instance variables for the information that is common to all animals: private String kind_of_animal; private String name; private String owner_name; private Calendar date_of_birth; Provide a constructor that has parameters of the same name and type: public Animal(String kind_of_animal, String name, String owner_name, Calendar dob)

Provide accessor methods for all instance variables. Same name as the instance variable with first letter capitalized. Provide a toString method. See test run.

Create class Dog as a derived class from class Animal. Let class Dog have instance variables private String breed; private String favorite_treat; 7 Class Dog The constructor for class Dog should have parameters for breed and favorite treat, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Dog. public Dog(String name, String owner_name, Calendar dob, String breed, String favorite_treat) 8 Class Dog Provide accessor methods for all instance variables specific to class Dog. Provide a toString method.

Add class Cat, derived from class Animal. Cats have the following attributes in addition to those of class Animal: Breed Preferred Catfood 11 Class Cat The constructor for class Cat should have parameters for breed and preferred catfood, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Cat. public Cat(String name, String owner_name, Calendar dob, String breed, String preferred_catfood) 12 Class Cat Provide accessor methods for all instance variables specific to class Cat. Provide a toString method

Create class Bird as a derived class from class Animal. Let class Bird have instance variables private String species; private double wingspan; 15 Class Bird The constructor for class Bird should have parameters for the instance variables that are specific to class Bird, in addition to the parameters for class Animal Except it doesn't need kind_of_animal, because we know that will be Bird. public Bird(String name, String owner_name, Calendar dob, String species, double wingspan) 16 Class Bird Provide accessor methods for all instance variables specific to class Bird. Provide a toString method

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Test programs:

Explanation / Answer

// Animal.java

import java.util.Calendar;

public class Animal{
   private String kind_of_animal;
   private String name;
   private String owner_name;
   private Calendar date_of_birth;
   public String getKind_of_animal() {
       return Character.toUpperCase(kind_of_animal.charAt(0)) + kind_of_animal.substring(1);
   }
   public String getName() {
       return Character.toUpperCase(kind_of_animal.charAt(0)) + name.substring(1);
   }
   public String getOwner_name() {
       return Character.toUpperCase(owner_name.charAt(0)) + owner_name;
   }
   public Calendar getDate_of_birth() {
       return date_of_birth;
   }
   public Animal(String kind_of_animal, String name, String owner_name, Calendar date_of_birth) {
       this.kind_of_animal = kind_of_animal;
       this.name = name;
       this.owner_name = owner_name;
       this.date_of_birth = date_of_birth;
   }
   public String toString() {
       return "Kind: " + kind_of_animal + ", Name: " + name + ", Owner: " + owner_name + ", Date of Birth: " + date_of_birth;
   }
}

// Dog.java

import java.util.Calendar;

public class Dog extends Animal{
   private String breed;
   private String favorite_treat;
   public Dog(String name, String owner_name, Calendar date_of_birth, String breed, String favorite_treat) {
       super("Dog", name, owner_name, date_of_birth);
       this.breed = breed;
       this.favorite_treat = favorite_treat;
   }
   public String getBreed() {
       return breed;
   }
   public String getFavorite_treat() {
       return favorite_treat;
   }
   public String toString() {
       return super.toString() + ", Breed: " + breed + ", Favourite treat: " + favorite_treat;
   }  
}

// Cat.java

import java.util.Calendar;

public class Cat extends Animal{
   private String breed;
   private String preferredCatfood;
   public Cat(String name, String owner_name, Calendar date_of_birth, String breed, String preferredCatfood) {
       super("Cat", name, owner_name, date_of_birth);
       this.breed = breed;
       this.preferredCatfood = preferredCatfood;
   }
   public String toString() {
       return super.toString() + ", Breed: " + breed + ", Preferred Catfood: " + preferredCatfood;
   }
   public String getBreed() {
       return breed;
   }
   public String getPreferredCatfood() {
       return preferredCatfood;
   }
}

// Bird.java

import java.util.Calendar;

public class Bird extends Animal{
   private String species;
   private double wingspan;
   public Bird(String name, String owner_name, Calendar date_of_birth, String species, double wingspan) {
       super("Bird", name, owner_name, date_of_birth);
       this.species = species;
       this.wingspan = wingspan;
   }
   public String getSpecies() {
       return species;
   }
   public double getWingspan() {
       return wingspan;
   }
   public String toString() {
       return super.toString() + ", Species: " + species + ", Wingspan: " + wingspan;
   }
}

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