SHARE
TWEET

Untitled

advictoriam Feb 28th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Animals
  2. {
  3.    /**
  4.       Describes the given animal.
  5.       @param pet an animal
  6.       @return a string with the animal's name, a space, and
  7.       either the trick that the animal knows (if it is a dog) or a
  8.       string "has no tricks"
  9.    */
  10.    public static String describe(Animal pet)
  11.    {
  12.       String trick =
  13.       trick = (pet instanceof Dog) ? ((Dog)pet).getTrick() : "has no tricks";
  14.       return String.format("%s %s", pet.getName(), trick);
  15.    }
  16.  
  17.    // This method is used to check your work
  18.    public static String check(String name, String trick)
  19.    {
  20.       Animal pet;
  21.       if (trick == null) pet = new Cat(name);
  22.       else pet = new Dog(name, trick);
  23.       return describe(pet);
  24.    }      
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top