Question: Write the code to define the class Pet, Pet needs to implement Comparable and has attributes name (a string) and age (an integer), Assume that

 Write the code to define the class Pet, Pet needs to

Write the code to define the class Pet, Pet needs to implement Comparable and has attributes name (a string) and age (an integer), Assume that pets are compared using their age and their name (take advantage of the fact that Strings already have a compareTo method), with age being the primary (first) criteria. Pet should have a single constructor that takes in the name and age as arguments. Pet needs (to override) the toString method that returns "Name = x, age = y", where x and y are the name and age of the pet. Pet should also override the equals method. So, you'll need are 0) The proper class definition 1) the data, 2) a compareTo method, 3) an equals (overridden) method, 4) the constructors, and 5) the toString methods. Do not write other methods or getters/setters

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!