/Animal

Animal

Primary LanguageJava

Animal
Assignment

  1. Can you implement the sing() method for the bird?
    a. How did you unit test it?
    -> using ByteArrayOutputStream for test system.out.println
    b. How did you optimize the code for maintainability?
    (Ask yourself the same question for all following exercises)
    -> Should use interface for action method and make it on new package or new class, group by something

Now, we have 2 special kinds of birds: the Duck and the Chicken… Can you implement them to make their own special sound?
a. A duck says: “Quack, quack” -> YES
b. A duck can swim ->YES
c. A chicken says: “Cluck, cluck” -> YES
d. A chicken cannot fly (assumption: its wings are clipped but ignore that) ->YES

Now how would you model a rooster?
a. A rooster says: “Cock-a-doodle-doo” -> YES
b. How is the rooster related to the chicken? -> Rooster is children of Chicken
c. Can you think of other ways to model a rooster without using inheritance? -> we are using interface toimplement action Rooster need, so dont need using inheritance

  1. Can you model a parrot? We are specifically interested in three parrots, one that
    lived in a house with dogs one in a house with cats, the other lived on a farm next to
    the rooster.
    a. A parrot living with dogs says: “Woof, woof” -> YES
    b. A parrot living with cats says: “Meow” -> YES
    c. A parrot living near the rooster says: “Cock-a-doodle-doo” -> YES
    d. How do you keep the parrot maintainable? What if we need another parrot
    lives near a Duck? Or near a phone that rings frequently?
    -> I try using Abstract class for Parrot in general with implement interface sing, then If you are parrot near dog just create new class and extend from this Parrot then you must have method sing.

B. Model fish as well as other swimming animals

  1. In addition to the birds, can you model a fish?
    a. Fishes don’t sing -> YES
    b. Fishes don’t walk - YES
    c. Fishes can swim -> YES
  1. Can you specialize the fish as a Shark and as a Clownfish?
    a. Sharks are large and grey -> YES
    b. Clownfish are small and colourful (orange) -> YES
    c. Clownfish make jokes -> YES
    d. Sharks eat other fish -> YES

  1. Can you optimize your model to account for the metamorphosis from caterpillar to butterfly?
    a. A caterpillar cannot fly -> YES
    b. A caterpillar can walk (crawl) -> YES

Can you share the code to count:-> YES