advictoriam Feb 28th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public class Animals
- Describes the given animal.
- @param pet an animal
- @return a string with the animal's name, a space, and
- either the trick that the animal knows (if it is a dog) or a
- string "has no tricks"
- public static String describe(Animal pet)
- String trick =
- trick = (pet instanceof Dog) ? ((Dog)pet).getTrick() : "has no tricks";
- return String.format("%s %s", pet.getName(), trick);
- // This method is used to check your work
- public static String check(String name, String trick)
- Animal pet;
- if (trick == null) pet = new Cat(name);
- else pet = new Dog(name, trick);
- return describe(pet);
RAW Paste Data