I need help with this project in a Java Language [lease, thank you in advance. I
ID: 3693640 • Letter: I
Question
I need help with this project in a Java Language [lease, thank you in advance. 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. Then; Create class Dog as a derived class from class Animal. Let class Dog have instance variables private String breed; private String favorite_treat; . 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) . Provide accessor methods for all instance variables specific to class Dog. Provide a toString method. See test run. Add class Cat, derived from class Animal. Cats have the following attributes in addition to those of class Animal: Breed Preferred Catfood . 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) . Provide accessor methods for all instance variables specific to class Cat. Provide a toString method. See test run. Create class Bird as a derived class from class Animal. Let class Bird have instance variables private String species; private double wingspan;. 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) . Provide accessor methods for all instance variables specific to class Bird. Provide a toString method. See test run.
Explanation / Answer
public class Animal
{
private String kind_of_animal;
private String name;
private String owner_name;
private Calendar date_of_birth;
public Animal(String kind_of_animal, String name, String owner_name, Calendar dob)
{
this.kind_of_animal= kind_of_animal;
this.name=name;
this.owner_name= owner_name;
this.date_of_birth= date_of_birth;
}
public Animal( String name, String owner_name, Calendar dob)
{
this.name=name;
this.owner_name= owner_name;
this.date_of_birth= date_of_birth;
}
//getter and setter methods
public String getKind_of_animal()
{
return kind_of_animal;
}
public void setKind_of_animal (String kind_of_animal)
{
this.kind_of_animal= kind_of_animal;
}
public String getName()
{
return name;
}
public void setName (String name)
{
this.name = name;
}
public String getOwner_name ()
{
return owner_name;
}
public void setOwner_name (String owner_name)
{
this. owner_name = owner_name;
}
public Calendar getDate_of_birth ()
{
return date_of_birth;
}
public void setDate_of_birth (Calendar date_of_birth)
{
this.date_of_birth = date_of_birth;
}
public String toString()
{
return name+"owner name"+ owner_name+"date of birth" +date_of_birth;
}
}
public class Dog extends Animal
{
private String breed;
private String favorite_treat;
public Dog(String name, String owner_name, Calendar dob, String breed, String favorite_treat)
{
super( String name, String owner_name, Calendar dob);
this.breed=breed;
this. favorite_treat= favorite_treat;
}
public String getBreed()
{
return breed;
}
public void setBreed(String breed)
{
this.breed= breed;
}
public String getFavorite_treat ()
{
return favorite_treat;
}
public void setFavorite_treat (String favorite_treat)
{
this.favorite_treat = favorite_treat;
}
public String toString()
{
return super. toString() + " breed"+breed+" favorite treat "+ favorite_treat;
}
}
public class Cat extends Animal
{
private String breed;
private String preferred_catfood;
public Cat(String name, String owner_name, Calendar dob, String breed, String preferred_catfood)
{
super( String name, String owner_name, Calendar dob);
this.breed=breed;
this. preferred_catfood= preferred_catfood;
}
public String getBreed()
{
return breed;
}
public void setBreed(String breed)
{
this.breed= breed;
}
public String getPreferred_catfood()
{
return preferred_catfood;
}
public void setPreferred_catfood(String preferred_catfood)
{
this. preferred_catfood= preferred_catfood;
}
public String toString()
{
return super. toString() + " breed"+breed+" preferred_catfood"+ preferred_catfood;
}
}
public class Bird extends Animal
{
private String species;
private double wingspan;
public Cat(String name, String owner_name, Calendar dob, String species, double wingspan)
{
super( String name, String owner_name, Calendar dob);
this. species = species;
this. double wingspan = double wingspan;
}
public String getSpecies ()
{
return species;
}
public void setSpecies (String species)
{
this.species = species;
}
public double getWingspan ()
{
return wingspan;
}
public void setWingspan (double wingspan)
{
this.wingspan = wingspan;
}
public String toString()
{
return super. toString() + " species "+ species +" wingspan "+ wingspan;
}
}