AquaFish: A Fish in an Aquarium
Partial Interface

Inspired by Part I of the Marine Biology Simulation Case Study,
available from the College Board for face-to-face teaching purposes.


General Description

Objects of the AquaFish class represent fish that can swim in an aquarium. These fish have color, a location (represented as x, y coordinates), and a direction (facing right or facing left). Each fish also has a unique ID number to distinguish it from other fish.

For a fish in an aquarium, the format produced by the ToString method is:

    ID(C,X,Y,D)
        where ID is the fish's unique ID,
              C  is the fish's color,
              X  is its X coordinate in the aquarium,
              Y  is its Y coordinate in the aquarium, and
              D  is the direction it is facing ('R' = right, 'L' = left)

The following object invariant is always true for an AquaFish instance:

    FacingRight() == ! FacingLeft()  and
    InAquarium() implies that the X and Y Coordinates represent valid
                         locations in the aquarium.

Author: Alyce Brady
Created: 7/1/99

Acknowledgements: This class is part of the Aquarium Lab Series, which was inspired by the College Board AP CS Marine Biology Case Study.

This AquaFish class is NOT the same as the AquaFish class in Part I of the Case Study, but is loosely based on that class and the Fish class in Part II.



Partial Interface

class AquaFish
{
  public:

    // Constructors
        
        // Unless otherwise specified, new AquaFish fish are black and
        // are placed at a random valid location in the aquarium.
        // (This assumes that the aquarium has width and height greater
        // than 0.)  It is also possible to specify the color and
        // location of a new fish when it is constructed.

    AquaFish(Aquarium a);
        // postcondition: Color() == "black",
        //     InAquarium() implies the location of fish is a valid
        //     location in a, fish is facing right

    AquaFish(Aquarium a, apstring initColor);
        // postcondition: Color() == initColor,
        //     InAquarium() implies the location of fish is a valid
	//     location in a, fish is facing right

    // Observer Functions

    int Id()                  const;
        // postcondition: returns unique id number of fish

    apstring Color()            const;
        // postcondition: returns fish color

    bool InAquarium()         const;
        // postcondition: returns true iff fish was constructed or has
        //     been placed in an aquarium with width and height > 0

    bool FacingWall()         const;
        // precondition:  InAquarium() is true
        // postcondition: returns true if the fish is against a wall and
        //                is facing it

    int XCoord()              const;
        // precondition:  InAquarium() is true
        // postcondition: returns x-coordinate of current fish position

    int YCoord()              const;
        // precondition:  InAquarium() is true
        // postcondition: returns y-coordinate of current fish position

    apstring ToString()         const;    
        // postcondition: returns a stringized form of AquaFish

    // Modifier Functions

    void MoveForward();
        // precondition:  InAquarium() is true
        // postcondition: fish has moved forward one space in the
        //                current direction

    void ChangeDir();
        // precondition:  InAquarium() is true
        // postcondition: fish is now facing in the opposite direction

  private:
     // not part of the public interface
};