Class Animal

java.lang.Object
  |
  +--Animal
Direct Known Subclasses:
Bird, Mammal

public abstract class Animal
extends java.lang.Object

An abstract class for animals

Since:
JDK1.2

Constructor Summary
Animal(java.lang.String name, double weight, java.lang.String food, java.lang.String motion)
          Creates an awake animal with a specific name, weight, favorite food, and method of locomotion.
 
Method Summary
 void feed()
          Feeds the animal.
 java.lang.String getName()
          Gets the animal's name.
 double getWeight()
          Gets the animal's weight.
abstract  java.lang.String poke()
          Pokes the animal, causing it to make noise if it can.
 void poop()
          Lets the animal poop.
 void sleep()
          Makes the animal go to sleep.
 java.lang.String toString()
          Returns a string representation of the animal.
 void wakeup()
          Makes the animal wake up.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Animal

public Animal(java.lang.String name,
              double weight,
              java.lang.String food,
              java.lang.String motion)
Creates an awake animal with a specific name, weight, favorite food, and method of locomotion.

Parameters:
name - the animal's name ("Fred", "Tweety", "Fido", etc.)
weight - the animal's initial weight, in kilograms
food - the animal's favorite food
motion - how the animal gets around
Method Detail

wakeup

public void wakeup()
Makes the animal wake up.


sleep

public void sleep()
Makes the animal go to sleep.


feed

public void feed()
Feeds the animal. This causes its weight to increase by 5%.


poop

public void poop()
Lets the animal poop. This causes its weight to decrease by 5%.

Returns:
the animal's new weight, in kilos

getName

public java.lang.String getName()
Gets the animal's name.

Returns:
the animal's name

getWeight

public double getWeight()
Gets the animal's weight.

Returns:
the animal's new weight, in kilos

poke

public abstract java.lang.String poke()
Pokes the animal, causing it to make noise if it can.

Returns:
the noise made by the animal

toString

public java.lang.String toString()
Returns a string representation of the animal. This includes its name, its current weight, what it likes to eat, and any noises it can make.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the animal