For this lab, you will need the Dog code that you developed in CSA. If you do not have access to this code, it is ok to get one of your classmates to send you their Dog code for you to start with.
In your tester class, create a heterogeneous array of ten Dogs called pack. In the array, insert two regular dogs, one Poodle, two Beagles, one Chihuahua, and four Basenji. Modify the Dog class to add the Comparable Interface to the class. Write the compareTo() method to compare Dogs based on their ages. Dogs that are younger should appear to the left of heavier dogs. Then use the following library sort method to sort the dogs in your array by age. Print the array of dogs before and after sorting. You will need to write a static array print method to print the array.
print(pack); // call static print method to print the heterogenous array of Dogs
Arrays.sort(pack); // since Dog class has implemented Comparable, this should work.
print(pack); // now the Dogs should be sorted by age.
Save your code from above but make a copy. Now go back and remove the Comparable interface from the Dog class. In your test code, write a custom comparator called c for the Dog class. This time, implement the compare method to sort by name (sort alphabetically). Note that the String class already has a compareTo method built in to help you do this. In your test code, sort the dogs by name using your new comparator. Be sure to print the array before and after sorting.
print(pack);
Arrays.sort(pack, c); // this time, the array is sorted in alphabetical order by the dogs' names.
print(pack);
Be sure to demo both versions of the lab to your instructor.