|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectfishPond.Fish
public class Fish
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.)
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 |
---|
public static final int FISH_STARTING_SIZE
public static final int MAX_FISH_SIZE
public static final int LEFT
public static final int RIGHT
public static final int UP
public static final int DOWN
Constructor Detail |
---|
public Fish(int rowIn, int colIn, int size, int direction)
public Fish(Fish other)
Method Detail |
---|
public void eat(int nutritionalValue)
public boolean isAlive()
public void shrink()
public java.lang.String toString()
toString
in class java.lang.Object
public void fight(Fish other)
public void move()
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.
public void setRandomDirection()
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).
public int getSize()
public int getRow()
public int getCol()
public int getDirection()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |