Minnow Project

Class Minnow

java.lang.Object
  |
  +--Minnow
All Implemented Interfaces:
Locatable

public class Minnow
extends java.lang.Object
implements Locatable

Minnow Program:
The Minnow class represents a simple fish in an environment. It is similar to, but simpler than, the Fish class in the Marine Biology Simulation Case Study.

When moving on to the Marine Biology Simulation case study, notice the following differences between the Minnow and Fish classes:

      The Fish class has more instance variables and more constructors.
          (see pp. 27 - 30 of the MBS case study narrative)
      Fish check that they are still in the environment before acting.
          (p. 33)
      Fish methods use the changeDirection helper method and the
          environment, location, and direction accessor methods.  (p. 39)
      The Fish helper methods are protected, not private.  (pp. 30, 65)
  

Version:
1 September 2002
See Also:
Environment, Direction, Location

Constructor Summary
Minnow(Environment env, Location loc)
          Constructs a minnow at the specified location in a given environment.
 
Method Summary
 void act()
          Acts for one step in the simulation.
 java.awt.Color color()
          Returns this minnow's color.
 Direction direction()
          Returns this minnow's direction.
 Environment environment()
          Returns this minnow's environment.
 Location location()
          Returns this minnow's location.
 java.lang.String toString()
          Returns a string representing key information about this minnow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Minnow

public Minnow(Environment env,
              Location loc)
Constructs a minnow at the specified location in a given environment. The Minnow is assigned a random direction and random color. (Precondition: parameters are non-null; loc is valid for env.)
Parameters:
env - environment in which minnow will live
loc - location of the new minnow in env
Method Detail

environment

public Environment environment()
Returns this minnow's environment.
Returns:
the environment in which this minnow lives

color

public java.awt.Color color()
Returns this minnow's color.
Returns:
the color of this minnow

location

public Location location()
Returns this minnow's location.
Specified by:
location in interface Locatable
Returns:
the location of this minnow in the environment

direction

public Direction direction()
Returns this minnow's direction.
Returns:
the direction in which this minnow is facing

toString

public java.lang.String toString()
Returns a string representing key information about this minnow.
Overrides:
toString in class java.lang.Object
Returns:
a string indicating the minnow's location and direction

act

public void act()
Acts for one step in the simulation.

Minnow Project

Copyright© 2002-2003 Alyce Brady