fishPond
Class Fish

java.lang.Object
  extended by fishPond.Fish

public class Fish
extends java.lang.Object

The state of a fish consists of its position in the pond (row and column), it's size, and the direction in which it is moving (UP, DOWN, LEFT, or RIGHT).

A fish moves, eats other fish, eats plants, and shrinks over time.

STUDENTS MAY NOT ADD ANY FIELDS OR PUBLIC METHODS! (You may add private methods of your own, if you wish.)

Author:
Put Your Name Here

Field Summary
static int DOWN
          Code for "Down" fish direction
static int FISH_STARTING_SIZE
          Initial size of each fish when simulation begins
static int LEFT
          Code for "Left" fish direction
static int MAX_FISH_SIZE
          Maximum size for a fish
static int RIGHT
          Code for "Right" fish direction
static int UP
          Code for "Up" fish direction
 
Constructor Summary
Fish(Fish other)
          Standard copy constructor -- just copies the fields
Fish(int rowIn, int colIn, int size, int direction)
          Simply initializes the state of the fish with these parameters
 
Method Summary
 void eat(int nutritionalValue)
          Fish size increased by nutritionalValue.
 void fight(Fish other)
          The current object battles the parameter (other).
 int getCol()
          Returns column
 int getDirection()
          Returns direction (UP, DOWN, LEFT, or RIGHT)
 int getRow()
          Returns row
 int getSize()
          Returns size
 boolean isAlive()
          Returns true if size is greater than zero, false otherwise
 void move()
          The fish's location (row or col) is adjusted by ONE unit, depending on the fish's current direction.
 void setRandomDirection()
          The fish's direction is randomly determined (UP, DOWN, LEFT or RIGHT).
 void shrink()
          Size is decreased by TWO.
 java.lang.String toString()
          Implement this however you want -- it's for your own purposes while debugging
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FISH_STARTING_SIZE

public static final int FISH_STARTING_SIZE
Initial size of each fish when simulation begins

See Also:
Constant Field Values

MAX_FISH_SIZE

public static final int MAX_FISH_SIZE
Maximum size for a fish

See Also:
Constant Field Values

LEFT

public static final int LEFT
Code for "Left" fish direction

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Code for "Right" fish direction

See Also:
Constant Field Values

UP

public static final int UP
Code for "Up" fish direction

See Also:
Constant Field Values

DOWN

public static final int DOWN
Code for "Down" fish direction

See Also:
Constant Field Values
Constructor Detail

Fish

public Fish(int rowIn,
            int colIn,
            int size,
            int direction)
Simply initializes the state of the fish with these parameters


Fish

public Fish(Fish other)
Standard copy constructor -- just copies the fields

Method Detail

eat

public void eat(int nutritionalValue)
Fish size increased by nutritionalValue.


isAlive

public boolean isAlive()
Returns true if size is greater than zero, false otherwise


shrink

public void shrink()
Size is decreased by TWO.


toString

public java.lang.String toString()
Implement this however you want -- it's for your own purposes while debugging

Overrides:
toString in class java.lang.Object

fight

public void fight(Fish other)
The current object battles the parameter (other). Whichever one is larger eats the other by calling the private "eat" method. In cases where the sizes of the two fish are exactly the same, have the current object win!


move

public void move()
The fish's location (row or col) is adjusted by ONE unit, depending on the fish's current direction. For example, if the current direction is "UP", then the fish's row should be decremented.

If the fish's current direction is not equal to one of the static constants UP, DOWN, LEFT, or RIGHT, then this method will throw an IllegalFishDirectionException, passing the fish's direction to the constructor. STUDENTS: You are required to use a switch statement when implementing this method.


setRandomDirection

public void setRandomDirection()
The fish's direction is randomly determined (UP, DOWN, LEFT or RIGHT). Sometimes the resulting direction will be the same as the original one.

YOU MUST FOLLOW THE INSTRUCTIONS BELOW OR YOU WILL NOT PASS OUR TESTS!

Call Random131.getRandomInteger(4).

If the value is 0, set the direction to UP. If 1, set to DOWN. If 2, set to LEFT. If 3, set to RIGHT. IMPORTANT: DO NOT SET THE DIRECTION TO THE VALUES 0, 1, 2, OR 3 -- directions must be set using the static constants (UP, DOWN, LEFT, RIGHT).


getSize

public int getSize()
Returns size


getRow

public int getRow()
Returns row


getCol

public int getCol()
Returns column


getDirection

public int getDirection()
Returns direction (UP, DOWN, LEFT, or RIGHT)



Web Accessibility