Class Animal

java.lang.Object
  extended by Animal
Direct Known Subclasses:
Fox, Rabbit

public abstract class Animal
extends Object

A class representing shared characteristics of animals.

Version:
2011.07.31
Author:
David J. Barnes and Michael Kölling

Constructor Summary
Animal(Field field, Location location)
          Create a new animal at location in field.
 
Method Summary
abstract  void act(List<Animal> newAnimals)
          Make this animal act - that is: make it do whatever it wants/needs to do.
protected  Field getField()
          Return the animal's field.
protected  Location getLocation()
          Return the animal's location.
protected  boolean isAlive()
          Check whether the animal is alive or not.
protected  void setDead()
          Indicate that the animal is no longer alive.
protected  void setLocation(Location newLocation)
          Place the animal at the new location in the given field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Animal

public Animal(Field field,
              Location location)
Create a new animal at location in field.

Parameters:
field - The field currently occupied.
location - The location within the field.
Method Detail

act

public abstract void act(List<Animal> newAnimals)
Make this animal act - that is: make it do whatever it wants/needs to do.

Parameters:
newAnimals - A list to receive newly born animals.

getField

protected Field getField()
Return the animal's field.

Returns:
The animal's field.

getLocation

protected Location getLocation()
Return the animal's location.

Returns:
The animal's location.

isAlive

protected boolean isAlive()
Check whether the animal is alive or not.

Returns:
true if the animal is still alive.

setDead

protected void setDead()
Indicate that the animal is no longer alive. It is removed from the field.


setLocation

protected void setLocation(Location newLocation)
Place the animal at the new location in the given field.

Parameters:
newLocation - The animal's new location.