In: Computer Science
Make Animal an abstract class.
Using the code below:
public class Animal { //Declaring instance variables private int age; private boolean RabiesVaccinationStatus; private String name; private String ownerName; //Zero argumented constructor public Animal() { } //Parameterized constructor public Animal(int age, boolean rabiesVaccinationStatus, String name, String ownerName) { this.age = age; RabiesVaccinationStatus = rabiesVaccinationStatus; this.name = name; this.ownerName = ownerName; } // getters and setters public int getAge() { return age; } public void setAge(int age) { this.age = age; } public boolean isRabiesVaccinationStatus() { return RabiesVaccinationStatus; } public void setRabiesVaccinationStatus(boolean rabiesVaccinationStatus) { RabiesVaccinationStatus = rabiesVaccinationStatus; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getOwnerName() { return ownerName; } public void setOwnerName(String ownerName) { this.ownerName = ownerName; } //toString method is used to display the contents of an object inside it public String toString() { return "Age :" + age + ", Rabies Vaccination Status :" + RabiesVaccinationStatus + ", Name :" + name + ", Owner Name :" + ownerName; } } // Dog.java class Dog extends Animal { //Declaring instance variables private boolean distemperVaccinationStatus; //Parameterized constructor public Dog(boolean distemperVaccinationStatus) { this.distemperVaccinationStatus = distemperVaccinationStatus; } //Parameterized constructor public Dog(int age, boolean rabiesVaccinationStatus, String name, String ownerName, boolean distemperVaccinationStatus) { super(age, rabiesVaccinationStatus, name, ownerName); this.distemperVaccinationStatus = distemperVaccinationStatus; } // getters and setters public boolean isDistemperVaccinationStatus() { return distemperVaccinationStatus; } public void setDistemperVaccinationStatus(boolean distemperVaccinationStatus) { this.distemperVaccinationStatus = distemperVaccinationStatus; } //toString method is used to display the contents of an object inside it public String toString() { return "Dog :"+super.toString() + " Distemper Vaccination Status :" + distemperVaccinationStatus; } public void speak() { System.out.println("bark"); } } // Cat,.java class Cat extends Animal { //Declaring instance variables private boolean felineLeukemiaVaccinationStatus; private boolean declawedStatus; //Parameterized constructor public Cat(boolean felineLeukemiaVaccinationStatus, boolean declawedStatus) { this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus; this.declawedStatus = declawedStatus; } //Parameterized constructor public Cat(int age, boolean rabiesVaccinationStatus, String name, String ownerName, boolean felineLeukemiaVaccinationStatus, boolean declawedStatus) { super(age, rabiesVaccinationStatus, name, ownerName); this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus; this.declawedStatus = declawedStatus; } // getters and setters public boolean isFelineLeukemiaVaccinationStatus() { return felineLeukemiaVaccinationStatus; } public void setFelineLeukemiaVaccinationStatus( boolean felineLeukemiaVaccinationStatus) { this.felineLeukemiaVaccinationStatus = felineLeukemiaVaccinationStatus; } public boolean isDeclawedStatus() { return declawedStatus; } public void setDeclawedStatus(boolean declawedStatus) { this.declawedStatus = declawedStatus; } //toString method is used to display the contents of an object inside it public String toString() { return "Cat :"+super.toString() + " Feline Leukemia Vaccination Status :" + felineLeukemiaVaccinationStatus + ", Declawed Status :" + declawedStatus; } public void speak() { System.out.println("Meow"); } }
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Animal.java
public abstract class Animal {
//Declaring instance variables
private int age;
private boolean RabiesVaccinationStatus;
private String name;
private String ownerName;
//Zero argumented constructor
public Animal() {
}
//Parameterized constructor
public Animal(int age, boolean
rabiesVaccinationStatus, String name,
String ownerName) {
this.age = age;
RabiesVaccinationStatus =
rabiesVaccinationStatus;
this.name = name;
this.ownerName = ownerName;
}
// getters and setters
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isRabiesVaccinationStatus() {
return RabiesVaccinationStatus;
}
public void setRabiesVaccinationStatus(boolean
rabiesVaccinationStatus) {
RabiesVaccinationStatus =
rabiesVaccinationStatus;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
//toString method is used to display the contents
of an object inside it
public String toString() {
return "Age :" + age + ", Rabies Vaccination Status
:"
+ RabiesVaccinationStatus + ", Name :" + name
+ ", Owner Name :" + ownerName;
}
public abstract void speak();
}
___________________________
// Cat.java
public class Cat extends Animal {
//Declaring instance variables
private boolean felineLeukemiaVaccinationStatus;
private boolean declawedStatus;
//Parameterized constructor
public Cat(boolean felineLeukemiaVaccinationStatus, boolean
declawedStatus) {
this.felineLeukemiaVaccinationStatus =
felineLeukemiaVaccinationStatus;
this.declawedStatus = declawedStatus;
}
//Parameterized constructor
public Cat(int age, boolean rabiesVaccinationStatus, String
name,
String ownerName, boolean felineLeukemiaVaccinationStatus,
boolean declawedStatus) {
super(age, rabiesVaccinationStatus, name, ownerName);
this.felineLeukemiaVaccinationStatus =
felineLeukemiaVaccinationStatus;
this.declawedStatus = declawedStatus;
}
// getters and setters
public boolean isFelineLeukemiaVaccinationStatus() {
return felineLeukemiaVaccinationStatus;
}
public void setFelineLeukemiaVaccinationStatus(
boolean felineLeukemiaVaccinationStatus) {
this.felineLeukemiaVaccinationStatus =
felineLeukemiaVaccinationStatus;
}
public boolean isDeclawedStatus() {
return declawedStatus;
}
public void setDeclawedStatus(boolean declawedStatus) {
this.declawedStatus = declawedStatus;
}
//toString method is used to display the contents of an object
inside it
public String toString() {
return "Cat :"+super.toString() + " Feline Leukemia Vaccination
Status :"
+ felineLeukemiaVaccinationStatus + ", Declawed Status :"
+ declawedStatus;
}
public void speak()
{
System.out.println("Meow");
}
}
___________________________
// Dog.java
public class Dog extends Animal {
//Declaring instance variables
private boolean distemperVaccinationStatus;
//Parameterized constructor
public Dog(boolean distemperVaccinationStatus) {
this.distemperVaccinationStatus = distemperVaccinationStatus;
}
//Parameterized constructor
public Dog(int age, boolean rabiesVaccinationStatus, String
name,
String ownerName, boolean distemperVaccinationStatus) {
super(age, rabiesVaccinationStatus, name, ownerName);
this.distemperVaccinationStatus = distemperVaccinationStatus;
}
// getters and setters
public boolean isDistemperVaccinationStatus() {
return distemperVaccinationStatus;
}
public void setDistemperVaccinationStatus(boolean
distemperVaccinationStatus) {
this.distemperVaccinationStatus = distemperVaccinationStatus;
}
//toString method is used to display the contents of an object
inside it
public String toString() {
return "Dog :"+super.toString() + " Distemper Vaccination Status
:"
+ distemperVaccinationStatus;
}
public void speak()
{
System.out.println("bark");
}
}
_________________________
// Kennel.java
public class Kennel {
public static void main(String[] args) {
Animal animals[]={new Dog(2,true,"Max","Ricky",true),
new
Dog(3,true,"Leo","Mike",true),
new
Dog(3,true,"Coffee","Sachin",false),
new
Cat(2,true,"Kitty","Rahul",true,true),
new
Cat(1,false,"Honey","Micheal",true,false),
new
Cat(1,false,"Mitty","Bobby",true,true)};
for(int i=0;i<animals.length;i++)
{
System.out.println(animals[i]);
}
}
}
__________________________
Output:
Dog :Age :2, Rabies Vaccination Status :true, Name
:Max, Owner Name :Ricky Distemper Vaccination Status :true
Dog :Age :3, Rabies Vaccination Status :true, Name :Leo, Owner Name
:Mike Distemper Vaccination Status :true
Dog :Age :3, Rabies Vaccination Status :true, Name :Coffee, Owner
Name :Sachin Distemper Vaccination Status :false
Cat :Age :2, Rabies Vaccination Status :true, Name :Kitty, Owner
Name :Rahul Feline Leukemia Vaccination Status :true, Declawed
Status :true
Cat :Age :1, Rabies Vaccination Status :false, Name :Honey, Owner
Name :Micheal Feline Leukemia Vaccination Status :true, Declawed
Status :false
Cat :Age :1, Rabies Vaccination Status :false, Name :Mitty, Owner
Name :Bobby Feline Leukemia Vaccination Status :true, Declawed
Status :true
_______________Could you plz rate me well.Thank You