📄 fish.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Aug 22 02:03:57 EDT 2002 --><TITLE>Marine Biology Simulation: Class Fish</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>AP® Computer Science Marine Biology Simulation</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="Environment.html"><B>PREV CLASS</B></A> <A HREF="Locatable.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="Fish.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2>Class Fish</H2><PRE>java.lang.Object | +--<B>Fish</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="Locatable.html">Locatable</A></DD></DL><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="DarterFish.html">DarterFish</A>, <A HREF="SlowFish.html">SlowFish</A></DD></DL><HR><DL><DT>public class <B>Fish</B><DT>extends java.lang.Object<DT>implements <A HREF="Locatable.html">Locatable</A></DL><P>AP® Computer Science Marine Biology Simulation:<br> A <code>Fish</code> object represents a fish in the Marine Biology Simulation. Each fish has a unique ID, which remains constant throughout its life. A fish also maintains information about its location and direction in the environment. <p> Modification History: - Modified to support a dynamic population in the environment: fish can now breed and die. <p> The <code>Fish</code> class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).<P><DL><DT><B>Version: </B><DD>1 July 2002</DD><DT><B>See Also: </B><DD><A HREF="Environment.html"><CODE>Environment</CODE></A>, <A HREF="Direction.html"><CODE>Direction</CODE></A>, <A HREF="Location.html"><CODE>Location</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="Fish.html#Fish(Environment, Location)">Fish</A></B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc)</CODE><BR> Constructs a fish at the specified location in a given environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="Fish.html#Fish(Environment, Location, Direction)">Fish</A></B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc, <A HREF="Direction.html">Direction</A> dir)</CODE><BR> Constructs a fish at the specified location and direction in a given environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="Fish.html#Fish(Environment, Location, Direction, java.awt.Color)">Fish</A></B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc, <A HREF="Direction.html">Direction</A> dir, java.awt.Color col)</CODE><BR> Constructs a fish of the specified color at the specified location and direction.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#act()">act</A></B>()</CODE><BR> Acts for one step in the simulation.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#breed()">breed</A></B>()</CODE><BR> Attempts to breed into neighboring locations.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#changeDirection(Direction)">changeDirection</A></B>(<A HREF="Direction.html">Direction</A> newDir)</CODE><BR> Modifies this fish's direction.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#changeLocation(Location)">changeLocation</A></B>(<A HREF="Location.html">Location</A> newLoc)</CODE><BR> Modifies this fish's location and notifies the environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> java.awt.Color</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#color()">color</A></B>()</CODE><BR> Returns this fish's color.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#die()">die</A></B>()</CODE><BR> Removes this fish from the environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="Direction.html">Direction</A></CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#direction()">direction</A></B>()</CODE><BR> Returns this fish's direction.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected java.util.ArrayList</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#emptyNeighbors()">emptyNeighbors</A></B>()</CODE><BR> Finds empty locations adjacent to this fish.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="Environment.html">Environment</A></CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#environment()">environment</A></B>()</CODE><BR> Returns this fish's environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#generateChild(Location)">generateChild</A></B>(<A HREF="Location.html">Location</A> loc)</CODE><BR> Creates a new fish with the color of its parent.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#id()">id</A></B>()</CODE><BR> Returns this fish's ID.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#isInEnv()">isInEnv</A></B>()</CODE><BR> Checks whether this fish is in an environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="Location.html">Location</A></CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#location()">location</A></B>()</CODE><BR> Returns this fish's location.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected void</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#move()">move</A></B>()</CODE><BR> Moves this fish in its environment.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="Location.html">Location</A></CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#nextLocation()">nextLocation</A></B>()</CODE><BR> Finds this fish's next location.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected java.awt.Color</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#randomColor()">randomColor</A></B>()</CODE><BR> Generates a random color.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> java.lang.String</CODE></FONT></TD><TD><CODE><B><A HREF="Fish.html#toString()">toString</A></B>()</CODE><BR> Returns a string representing key information about this fish.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.Object</B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait</CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="Fish(Environment, Location)"><!-- --></A><H3>Fish</H3><PRE>public <B>Fish</B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc)</PRE><DL><DD>Constructs a fish at the specified location in a given environment. The Fish is assigned a random direction and random color. (Precondition: parameters are non-null; <code>loc</code> is valid for <code>env</code>.)<DD><DL><DT><B>Parameters:</B><DD><CODE>env</CODE> - environment in which fish will live<DD><CODE>loc</CODE> - location of the new fish in <code>env</code></DL></DD></DL><HR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -