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 BoundedEnv

    java.lang.Object
      |
      +--SquareEnvironment
            |
            +--BoundedEnv

All Implemented Interfaces:
  Environment

public class BoundedEnv
extends SquareEnvironment

AP® Computer Science Marine Biology Simulation:
The `BoundedEnv` class models a bounded, two-dimensional, grid-like environment containing locatable objects. For example, it could be an environment of fish for a marine biology simulation.

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

Version:
  1 July 2002
See Also:
  `Locatable`, `Location`

Constructor Summary
`BoundedEnv(int rows, int cols)` Constructs an empty BoundedEnv object with the given dimensions.

Method Summary
`void` | `add(Locatable obj)` Adds a new object to this environment at the location it specifies.
`Locatable[]` | `allObjects()` Returns all the objects in this environment.
`boolean` | `isEmpty(Location loc)` Determines whether a specific location in this environment is empty.
`boolean` | `isValid(Location loc)` Verifies whether a location is valid in this environment.
`int` | `numCols()` Returns number of columns in the environment.
`int` | `numObjects()` Returns the number of objects in this environment.
`int` | `numRows()` Returns number of rows in the environment.
`Locatable` | `objectAt(Location loc)` Returns the object at a specific location in this environment.
`void` | `recordMove(Locatable obj, Location oldLoc)` Updates this environment to reflect the fact that an object moved.
`void` | `remove(Locatable obj)` Removes the object from this environment.
`java.lang.String` | `toString()` Creates a single string representing all the objects in this environment (not necessarily in any particular order).

Methods inherited from class SquareEnvironment
`getDirection, getNeighbor, neighborsOf, numAdjacentNeighbors, numCellSides, randomDirection`

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

Constructor Detail

### BoundedEnv

    public BoundedEnv(int rows,
                      int cols)

  Constructs an empty BoundedEnv object with the given dimensions. (Precondition: `rows > 0` and `cols > 0`.)
  Parameters:
    `rows` - number of rows in BoundedEnv
    `cols` - number of columns in BoundedEnv

Method Detail

### numRows

    public int numRows()

  Returns number of rows in the environment.
  Returns:
    the number of rows, or -1 if this environment is unbounded

### numCols

    public int numCols()

  Returns number of columns in the environment.
  Returns:
    the number of columns, or -1 if this environment is unbounded

### isValid

    public boolean isValid(Location loc)

  Verifies whether a location is valid in this environment.
  Parameters:
    `loc` - location to check
  Returns:
    `true` if `loc` is valid; `false` otherwise

### numObjects

    public int numObjects()

  Returns the number of objects in this environment.
  Returns:
    the number of objects

### allObjects

    public Locatable[] allObjects()

  Returns all the objects in this environment.
  Returns:
    an array of all the environment objects

### isEmpty

    public boolean isEmpty(Location loc)

  Determines whether a specific location in this environment is empty.
  Parameters:
    `loc` - the location to test
  Returns:
    `true` if `loc` is a valid location in the context of this environment and is empty; `false` otherwise

### objectAt

    public Locatable objectAt(Location loc)

  Returns the object at a specific location in this environment.
  Parameters:
    `loc` - the location in which to look
  Returns:
    the object at location `loc`; `null` if `loc` is not in the environment or is empty

### toString

    public java.lang.String toString()

  Creates a single string representing all the objects in this environment (not necessarily in any particular order).
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    a string indicating all the objects in this environment

### add

    public void add(Locatable obj)

  Adds a new object to this environment at the location it specifies. (Precondition: `obj.location()` is a valid empty location.)
  Parameters:
    `obj` - the new object to be added
  Throws:
    `java.lang.IllegalArgumentException` - if the precondition is not met

### remove

    public void remove(Locatable obj)

  Removes the object from this environment. (Precondition: `obj` is in this environment.)
  Parameters:
    `obj` - the object to be removed
  Throws:
    `java.lang.IllegalArgumentException` - if the precondition is not met

### recordMove

    public void recordMove(Locatable obj,
                           Location oldLoc)

  Updates this environment to reflect the fact that an object moved. (Precondition: `obj.location()` is a valid location and there is no other object there. Postcondition: `obj` is at the appropriate location (`obj.location()`), and either `oldLoc` is equal to `obj.location()` (there was no movement) or `oldLoc` is empty.)
  Parameters:
    `obj` - the object that moved
    `oldLoc` - the previous location of `obj`
  Throws:
    `java.lang.IllegalArgumentException` - if the precondition is not met

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