Question: Coding problem Using JAVA This is Main class, please do not alter: import java.util.ArrayList; import java.util.Collections; import java.util.List; public class AssignmentTwo { public static void
Coding problem Using JAVA

This is Main class, please do not alter:
import java.util.ArrayList; import java.util.Collections; import java.util.List;
public class AssignmentTwo {
public static void main(String[] args) { Cat cat1 = new Cat("Fluffy", 150); Cat cat2 = new Cat("Sweety", 200, "yellow"); Dog dog1 = new Dog("Duke", 10, 500); Dog dog2 = new Dog("Jason", 5); List animals = new ArrayList(); animals.add(cat1); animals.add(cat2); animals.add(dog1); animals.add(dog2); printAll("Before Sort", animals); Collections.sort(animals); printAll("After Sort", animals); System.out.println(""); for(Animal animal : animals) { System.out.println(" Animal " + animal + " is a " + animal.getType() + " speaks by " + animal.speaksBy()); animal.store(); animal.load(); } } private static void printAll(String title, List animals) { System.out.println(" " + title); for(Animal animal : animals) System.out.println(animal); }
}
This assignment uses Inheritance and Interfaces. You must use my AssignmentTwo.java without modifying You do not need Javadocs You need to create Animal, Cat, Dog, Storable and Talkable. Cat and Dog are subclasses of Animal. Storable and Talkable are Interfaces. The second argument to the constructors is the ordering key. For Dog use the positive value, for Cat use the negative value. This defines your compareTo(). This is desired output: Before Sort (Fluffy, 150), color = pink (Sweety, 200), color = yellow (Duke, 10), weight = 500.0 (Jason,5), weight = 100.0 After Sort (Sweety, 200), color = yellow (Fluffy, 150), color = pink (Jason,5), weight = 100.0 (Duke, 10), weight = 500.0 Animal (Sweety, 200), color = yellow is a kitty speaks by meowing (Sweety, 200), color = yellow being stored in first class (Sweety, 200), color = yellow being loaded into wooden box Animal (Fluffy, 150), color = pink is a kitty speaks by meowing (Fluffy, 150), color = pink being stored in first class (Fluffy, 150), color = pink being loaded into wooden box Animal (Jason,5), weight = 100.0 is a Doggie speaks by barking (Jason,5), weight = 100.0 being stored in coach (Jason,5), weight = 100.0 being loaded from Kennel Animal (Duke, 10), weight = 500.0 is a Doggie speaks by barking (Duke, 10), weight = 500.0 being stored in coach (Duke, 10), weight = 500.0 being loaded from kennel This assignment uses Inheritance and Interfaces. You must use my AssignmentTwo.java without modifying You do not need Javadocs You need to create Animal, Cat, Dog, Storable and Talkable. Cat and Dog are subclasses of Animal. Storable and Talkable are Interfaces. The second argument to the constructors is the ordering key. For Dog use the positive value, for Cat use the negative value. This defines your compareTo(). This is desired output: Before Sort (Fluffy, 150), color = pink (Sweety, 200), color = yellow (Duke, 10), weight = 500.0 (Jason,5), weight = 100.0 After Sort (Sweety, 200), color = yellow (Fluffy, 150), color = pink (Jason,5), weight = 100.0 (Duke, 10), weight = 500.0 Animal (Sweety, 200), color = yellow is a kitty speaks by meowing (Sweety, 200), color = yellow being stored in first class (Sweety, 200), color = yellow being loaded into wooden box Animal (Fluffy, 150), color = pink is a kitty speaks by meowing (Fluffy, 150), color = pink being stored in first class (Fluffy, 150), color = pink being loaded into wooden box Animal (Jason,5), weight = 100.0 is a Doggie speaks by barking (Jason,5), weight = 100.0 being stored in coach (Jason,5), weight = 100.0 being loaded from Kennel Animal (Duke, 10), weight = 500.0 is a Doggie speaks by barking (Duke, 10), weight = 500.0 being stored in coach (Duke, 10), weight = 500.0 being loaded from kennel
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
