3. Given the following code import java.util.ArrayList; import java.util.Compara
ID: 3706583 • Letter: 3
Question
3. Given the following code import java.util.ArrayList; import java.util.Comparator; import java.util.Collections; public class Cat implements Comparable t public int age; public String nane: public Cat (int age, String name) ( this.ageage; this.namename private static class CatComparator implenents Comparator t public int compare(T a, T b) ( if (a.compareTo(b)0) return a.nase.compareTo(b.name); return a.compareTo(b); public int compareTo (Object other) Cat that-(Cat) (other); return this.age- that.age; public static void main(String] args) t ArrayList cats ne ArrayListo cats.add (new Cat (8, "steph")) cats.add (new Cat (4, "adi")) cats.add (new Cat(5, "chris")) cats.add (new Cat (2, "taylor")) cats.add (new Cat (4, "sam) CatComparator catComp-ne CatComparatorExplanation / Answer
2)(a)
c) taylor adi sam chris Steph
_________________
2(b)
A) andy, john
__________________
4)
Go Jackets!
Still Cheering
__________________Thank You
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.