Class | Tree | Index | Help
| AP® Computer Science Marine Biology Simulation
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class DarterFish

    java.lang.Object
      |
      +--Fish
            |
            +--DarterFish

All Implemented Interfaces:
  Locatable

public class DarterFish
extends Fish

AP® Computer Science Marine Biology Simulation:
The `DarterFish` class represents a fish in the Marine Biology Simulation that darts forward two spaces if it can, moves forward one space if it can't move two, and reverses direction (without moving) if it cannot move forward. It can only "see" an empty location two cells away if the cell in between is empty also. In other words, if both the cell in front of the darter and the cell in front of that cell are empty, the darter fish will move forward two spaces. If only the cell in front of the darter is empty, it will move there. If neither forward cell is empty, the fish will turn around, changing its direction but not its location.

`DarterFish` objects inherit instance variables and much of their behavior from the `Fish` class.

The `DarterFish` class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
  1 July 2002

Constructor Summary
`DarterFish(Environment env, Location loc)` Constructs a darter fish at the specified location in a given environment.
`DarterFish(Environment env, Location loc, Direction dir)` Constructs a darter fish at the specified location and direction in a given environment.
`DarterFish(Environment env, Location loc, Direction dir, java.awt.Color col)` Constructs a darter fish of the specified color at the specified location and direction.

Method Summary
`protected void` | `generateChild(Location loc)` Creates a new darter fish.
`protected void` | `move()` Moves this fish in its environment.
`protected Location` | `nextLocation()` Finds this fish's next location.

Methods inherited from class Fish
`act, breed, changeDirection, changeLocation, color, die, direction, emptyNeighbors, environment, id, isInEnv, location, randomColor, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### DarterFish

    public DarterFish(Environment env,
                      Location loc)

  Constructs a darter fish at the specified location in a given environment. This darter is colored yellow. (Precondition: parameters are non-null; `loc` is valid for `env`.)
  Parameters:
    `env` - environment in which fish will live
    `loc` - location of the new fish in `env`

### DarterFish

    public DarterFish(Environment env,
                      Location loc,
                      Direction dir)

  Constructs a darter fish at the specified location and direction in a given environment. This darter is colored yellow. (Precondition: parameters are non-null; `loc` is valid for `env`.)
  Parameters:
    `env` - environment in which fish will live
    `loc` - location of the new fish in `env`
    `dir` - direction the new fish is facing

### DarterFish

    public DarterFish(Environment env,
                      Location loc,
                      Direction dir,
                      java.awt.Color col)

  Constructs a darter fish of the specified color at the specified location and direction. (Precondition: parameters are non-null; `loc` is valid for `env`.)
  Parameters:
    `env` - environment in which fish will live
    `loc` - location of the new fish in `env`
    `dir` - direction the new fish is facing
    `col` - color of the new fish

Method Detail

### generateChild

    protected void generateChild(Location loc)

  Creates a new darter fish.
  Overrides:
    `generateChild` in class `Fish`
  Parameters:
    `loc` - location of the new fish

### move

    protected void move()

  Moves this fish in its environment. A darter fish darts forward (as specified in `nextLocation`) if possible, or reverses direction (without moving) if it cannot move forward.
  Overrides:
    `move` in class `Fish`

### nextLocation

    protected Location nextLocation()

  Finds this fish's next location. A darter fish darts forward two spaces if it can, otherwise it tries to move forward one space. A darter fish can only move to empty locations, and it can only move two spaces forward if the intervening space is empty. If the darter fish cannot move forward, `nextLocation` returns the fish's current location.
  Overrides:
    `nextLocation` in class `Fish`
  Returns:
    the next location for this fish

Class | Tree | Index | Help
| AP® Computer Science Marine Biology Simulation
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright© 2002 College Entrance Examination Board