Java homework problem. The class below describes a parent class, Pet. In the nex
ID: 3729482 • Letter: J
Question
Java homework problem.
The class below describes a parent class, Pet. In the next questions, you will write child classes for Cat and Bird.
For full credit, follow good principles of class design, encapsulation, and inheritance.
I recommend writing the class in your development environment to make sure it compiles and then copying the code into the appropriate question
public abstract class Pet {
private String name;
private int age;
public Pet(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if(age > 0) {
this.age = age;
}
}
public String toString() {
String s = "Name: " + name ;
s += " Age: " + age;
return s;
}
public abstract void printVetAppointmentReminder();
}
1.
Assume the Pet class implements Comparable. Write the new class header and the full compareTo method (including the method header).
Pets should be compared/ordered based on their name (ignoring case) and then their age.
For example, "Fluffy, 8 years old" would come before "Meowy, 3 years old" which would come before "Meowy, 5 years old."
2.
Write the class header and the instance data variables for the Cat class.
A cat is described by name, age, and color (stored as a String).
3.
Write a constructor for the Cat class that initializes a cat object by specifying all information as parameters.
4.
Write accessor and mutator (getter and setter) methods. Include validity checking where appropriate.
5.
Write a toString method to return a text representation of the cat that includes the name, age, and color.
6.
Write an equals method for the Cat class. Two cat objects are considered the same (logically equivalent) if they have the same name, age, and color.
7.
Is there anything else you need to add to your class so that it will compile? If so, include that here.
8.
Write the class header and the instance data variables for the Bird class.
A bird is described by name, age, and whether or not it can sing.
Please write the question number in front of the answer.
Explanation / Answer
2-7)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.