THe instructions are found below. They seem long, but its a simple assignment In
ID: 3693346 • Letter: T
Question
THe instructions are found below. They seem long, but its a simple assignment
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.
Download program Animal_Tester from the class web site, and use it to test your Animal class.
THIS IS THE ANIMAL TESTER
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.
Download program Dog_Tester from the class web site, and use it to test your Dog class.
DOG TESTER PROGRAM BELOW
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.
Download Cat_Tester.java from the class web site, and use it to test your Cat class.
CAT TEST BELOW
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.
Download program Bird_Tester from the class web site, and use it to test your Bird class.
BIRD TEST PROGRAM BELOW
Explanation / Answer
import java.util.*;
class Animal
{
private String kind_of_animal;
private String name;
private String owner_name;
private Calendar date_of_birth;
public Calendar Date_of_Birth()
{
return date_of_birth;
}
public String Kind_of_animal()
{
return kind_of_animal;
}
public String Name()
{
return name;
}
public String Owner_name()
{
return owner_name;
}
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=dob;
}
public String toString()
{
return "This is animal.";
}
}
class Cat extends Animal
{
private String breed;
private String preferred_catfood;
public String Breed()
{
return breed;
}
public String Preferred_catfood()
{
return preferred_catfood;
}
public Cat(String name, String owner_name, Calendar dob, String breed, String preferred_catfood)
{
super("cat",name,owner_name,dob);
this.breed=breed;
this.preferred_catfood=preferred_catfood;
}
public String toString()
{
return "This is a cat";
}
}
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("Dog",name,owner_name,dob);
this.breed=breed;
this.favorite_treat=favorite_treat;
}
public String Breed()
{
return breed;
}
public String Favorite_treat()
{
return favorite_treat;
}
public String toString()
{
return "This is a Dog";
}
}
class Bird extends Animal
{
private String species;
private double wingspan;
public String Species()
{
return species;
}
public double Wingspan()
{
return wingspan;
}
public Bird(String name, String owner_name, Calendar dob, String species, double wingspan)
{
super("bird",name,owner_name,dob);
this.wingspan=wingspan;
this.species=species;
}
public String toString()
{
return "This is a bird";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.