The class below describes a parent class, Pet. In the next questions, you will w
ID: 3678259 • Letter: T
Question
The class below describes a parent class, Pet. In the next questions, you will write child classes for Dog and Cat. 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 ordered based on their name (ignoring case) and then their age.
For example, "Fido, 8 years old" would come before "Spot, 3 years old" would come before "Spot, 5 years old."
2.
Write the class header and the instance data variables for the Dog class.
A dog is described by name, age, and breed (stored as a String).
3.Write a constructor for the Dog class that initializes a dog object by specifying all information.
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 dog that includes the name, age, and breed.
6.Write an equals method. Two Dog objects are considered the same (logically equivalent) if they have the same name, age, and breed.
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 Cat class.
A cat is described by name, age, and whether or not the cat is an indoor-only cat
9.Write a constructor for the Cat class that initializes a cat object by specifying all information.
10.Write accessor and mutator (getter and setter) methods. Include validity checking where appropriate.
11.Write a toString method to return a text representation of the cat that includes the name, age, and indoor status.
12.
Write code that would go inside a driver program with a main method.
Create an array to hold 6 Pet objects
Fill the array with some cats and some dogs.
Iterate the array and print a text representation of each pet.
Iterate the array and output the name of each outdoor cat.
Use polymorphism to do this!
Sort the array by invoking a Java-provided sorting method.
thanks
Explanation / Answer
Please find the answers below :
1)
2-7)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.