Question: java import java.util.ArrayList; import java.util.Collections; abstract class Pets { String name; String color; int age; int legs; boolean hair; public Pets(String name, String color, int
java
import java.util.ArrayList; import java.util.Collections; abstract class Pets { String name; String color; int age; int legs; boolean hair; public Pets(String name, String color, int age, int legs, boolean hair) { this.name = name; this.color = color; this.age = age; this.legs = legs; this.hair = hair; } public abstract void speak(); public abstract void move(); } class Dog extends Pets implements Comparable { public Dog(String name, String color, int age, int legs, boolean hair) { super(name, color,age, legs, hair); } public void speak() { System.out.println("The dog is speaking!"); } public void move() { System.out.println("The dog is moving!"); } public String getName() { return name; } public void getInfo() { System.out.print(name + " " + color + " " + age + " " ); if(hair == true) { System.out.println("Hair"); } else System.out.println("Hairless"); }
@Override public int compareTo(Object o) { Dog d = (Dog) o; return this.name.compareTo(d.getName()); }
}
public class HW_AP { public static void main(String[] args) { ArrayList
}}

REWORKING THE JOURNAL. Go back to last weeks assignment and see if you can perfect the Sort with the comparable interface. Now, Sort the List by First: Hair or Hairless Second: Age Example: Before Sort Dog Age Hair? Lad 10 True Lassie 5 True Sparkie 10 False Lassie 5 False Zeb 3 False After Sort Dog Age Hair? Zeb 3 False Lassie 5 False Sparkle 10 False Lassie 5 True Lad 10 True (HINT: Remember, the sort rules are all programmed in the compareTo() method ) Nothing changes in the Collections.Sort()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
