hie all, i am here all because of need u guys help..
my task is to create two fishes which can swim inside aquarium and move and turn by using java coding.
actually i got a set of uncompleted code.
what i need to do is to compile all the coding and make it works.
i tried million of times and still unable to work.
need help form u guys.. its urgent... pls....

Recommended Answers

All 7 Replies

Well, using my powers of telepathy and empathy, I will tell you that character 6 on line 225 of your second class should be c.

are you willing to help me..
i will send u the code..
i totally run out of idea how to do dis..:(

Of course, but we need more info (as my first reply, sarcastically, implied). Post all error/compiler messages, post your code, and post what the program produces and what it is suppossed to produce.

The Aquarium Simulation program is meant to simulate several fish moving in an aquarium. A skeleton of the program already exists. It contains seven classes:

AquaFish.java
Aquarium.java
AquariumController.java
AquaSimApplication.java
AquaSimGUI.java
AquaSimApplication.java
NavigationalAide.java

All these classes fall under the free software, which you can redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. You can obtain these classes from your lecturer.

The first task at hand is to compile this entire program and create the class file.

(AquaFish.java)

import java.awt.Color;
import java.util.Random;

/**
 * Aquarium Lab Series: <br>
 *      The AquaFish class defines a fish in an aquarium. 
 * <br> <br>
 * Created: <br>
 *   10 July 2002,  Alyce Brady<br>
 * <br>
 * Modifications: <br>
 *   22 March 2008, Alyce Brady, Simplified by removing references to
 *                               AquaPoint and Direction classes and moving
 *                               calculation of valid random starting locations
 *                               to the Aquarium class. <br>
 *   23 March 2008, Alyce Brady, Modified to put some of the more complex
 *                               methods in the NavigationAide class, to make
 *                               the AquaFish class easier to read. <br>
 *   (date), (your name), Modified to .... <br>
 * 
 * @author (your name) (with assistance from)
 * @version 23 March 2008
 * @see Aquarium
 **/
public class AquaFish 
{
    // STATE

    // Named constants that specify how far a fish may move in one timestep
    public static final int MIN_DISTANCE = 10;
    public static final int MAX_DISTANCE = 70;

    // Class Variables: Shared among ALL fish
    private static int nextAvailableID = 1;   // next avail unique identifier
    private static Random generator = new Random(); // random number generator

    // Instance Variables: Encapsulated data for EACH fish
    private Aquarium theAquarium;    // aquarium in which this fish is swimming
    private int uniqueID;            // unique identifier for this fish
    private Color color;             // fish's color
    private NavigationalAide aide;   // object that keeps track of this fish's
                                     //    size, location, and direction

    // OPERATIONS (constructor and methods)

    /**
     *  The AquaFish constructor sets properties of the AquaFish.
     *  Precondition: the aquarium must be big enough to accomodate
     *  the biggest fish (currently 75 pixels long and 30 pixels high)
     *  plus 10 pixels of padding in all four directions.
     *  @param    aqua   the Aquarium in which to place the fish
     **/
    public AquaFish(Aquarium aqua)
    {
        // Place fish in aquarium and initialize ID.
        this.theAquarium = aqua;
        this.uniqueID = nextAvailableID;
        nextAvailableID++;

        // Initialize fish's size, location, and direction.
        this.aide = new NavigationalAide(this);

        // Initialize this fish's color.
        this.color = Color.WHITE;
    }

    /**
     *  Gets the aquarium in which this fish moves.
     *  @return  the aquarium in which this fish exists
     */
    public Aquarium aquarium()
    {
        return this.theAquarium;
    }

    /**
     *  Gets the unique identifier for this fish.
     *  @return    the ID of the fish
     **/
    public int id()
    {
        return this.uniqueID;
    }

    /** Gets fish's color.
     *  @return        the color of this fish
     **/
    public Color color()
    {
        return this.color;
    }

    /**
     *  Gets this fish's x coordinate in the aquarium.
     *  @return    the x coordinate in the aquarium of the fish's centerpoint
     **/
    public int xCoord()
    {
        return aide.centerpointX();
    }

    /**
     *  Gets this fish's y coordinate in the aquarium.
     *  @return    the y coordinate in the aquarium of the fish's centerpoint
     **/
    public int yCoord()
    {
        return aide.centerpointY();
    }

    /**
     *  Determines whether this fish is facing right.
     *  @return     <code>true</code> if fish is facing right;
     *              <code>false</code> otherwise
     **/
    public boolean facingRight()
    {
        return aide.isFishFacingRight();
    }

    /**
     *  Determines whether this fish is facing left.
     *  @return     <code>true</code> if fish is facing left;
     *              <code>false</code> otherwise
     **/
    public boolean facingLeft()
    {
        return ! this.facingRight();
    }

    /**
     *  Determine whether this fish is at a wall.
     *  A fish is considered at a wall if it cannot move forward; in other
     *  words, if the distance from the fish to the wall it faces is less
     *  than the minimum distance that a fish can move forward.
     *  @returns    <code>true</code> if fish is at a wall;
     *              <code>false</code> otherwise
     **/
    public boolean atWall()
    {
        return (aide.fishDistanceToWall() <= MIN_DISTANCE);
    }

    /** Gets the length of this fish.
     *  @return   fish length
     **/
    public int length()
    {
        return aide.fishLength();
    }

    /** Gets the height of this fish.
     *  @return    fish height
     **/
    public int height()
    {
        return aide.fishHeight();
    }

    /**
     *  This function is provided primarily for debugging purposes.
     *  @return    a string representation of a fish
     **/
    public String toString()
    {
        String s = new String();
        s += this.uniqueID + aide.toString();
        return s;
    }

//     /** 
//      *  Moves the fish for one time step.
//      */
//     public void move()
//     {
//         this.moveForward();
//     }

    /**
     *  Moves forward horizontally by random increments, staying
     *  within the aquarium.
     **/
//    protected void moveForward()
    public void moveForward()
    {
        // First get random number in range [0, MAX_DISTANCE-MIN_DISTANCE],
        // then shift to [MIN_DISTANCE, MAX_DISTANCE].  If moving that
        // far would mean swimming out of the aquarium, only move to edge
        // of aquarium.  Adjust fish's x coordinate by a positive or 
        // negative amount, depending on whether fish is facing right or left.
        int moveAmt = generator.nextInt(MAX_DISTANCE - MIN_DISTANCE + 1);
        moveAmt += MIN_DISTANCE;
        if ( moveAmt >= aide.fishDistanceToWall() )
            moveAmt = aide.fishDistanceToWall();
        if ( aide.isFishFacingRight() )
            aide.moveFishRight(moveAmt);
        else
            aide.moveFishLeft(moveAmt);
    }

    /**
     *  Reverses direction.
     **/
//     protected void changeDir()
    public void changeDir()
    {
        aide.reverseFishDir();
    }

(Aquarium.java)

import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;

/**
 * Aquarium Lab Series: <br>
 *  The Aquarium class defines an Aquarium and its properties.
 * <br> <br>
 * Created: <br>
 *   10 July 2002,  Alyce Brady<br>
 * <br>
 * Modifications: <br>
 *   22 March 2008, Alyce Brady, Added randomCenterX and randomCenterY
 *                               methods, moving that logic from the old
 *                               AquaFish class to the Aquarium class.
 *   23 March 2008, Alyce Brady, Added list of fish to the aquarium to simplify
 *                               the display of an aquarium containing fish.
 *  @author  Alyce Brady
 *  @version 23 March 2008
 **/
public class Aquarium
{
    private static final Random generator = new Random();
    private int myWidth;
    private int myHeight;
    private int borderPadding;
    private Color myColor;
    private ArrayList<AquaFish> listOfFish;

    /**
        Constructs an Aquarium with user-specified size.
        @param    width    width of the aquarium when displayed (in pixels)
        @param    height   height of the aquarium when displayed (in pixels)
    */
    public Aquarium(int width, int height)
    {
        if (width > 0)
            myWidth = width;
        else
            myWidth = 640;
        if (height > 0)
            myHeight = height;
        else
            myHeight = 480;

        borderPadding = 10;

        myColor = new Color(0.0f, .6f, 1.0f);

        listOfFish = new ArrayList<AquaFish>();
    }

    /**
     *  Adds the given fish to this aquarium.
     */
    public void add(AquaFish fish)
    {
        listOfFish.add(fish);
    }

    /**
        Determines the width of the aquarium.
        @returns    the width of the aquarium
    */
    public int width()
    {
        return myWidth;
    }

    /**
        Determines the height of the aquarium.
        @returns    the height of the aquarium
    */
    public int height()
    {
        return myHeight;
    }

    /**
        Determines the color of the aquarium (water color).
        @returns    the Color of the aquarium
    */
    public Color color()
    {
        return myColor;
    }

    /**
     *  Returns a list of the fish in this aquarium.
     *    @returns  list of fish in this aquarium
     */
    public ArrayList<AquaFish> getFish()
    {
        return listOfFish;
    }

    /**
        Determines whether the given coordinates specify
            a valid location (one that exists within the bounds of the
            aquarium).
        @params     an x and y coordinate to be checked
        @returns    true if the specified location is within the bounds
                    of the aquarium
    */
    public boolean validLoc(int xCoord, int yCoord)
    {
        if ((0 <= xCoord && xCoord < myWidth) && 
                (0 <= yCoord && yCoord < myHeight))
            return true;
        return false;
    }

    /**
     *  Determines a valid random x coordinate for the centerpoint of
     *  an object with the given length along the x axis.
     *  Precondition: this aquarium must be big enough to accomodate
     *  the object with the given length, plus 10 pixels of padding in
     *  each direction.
     **/
    public int randomCenterX(int objectLength)
    {
        // The entire object should fit within the aquarium, so its
        // center x coordinate should be in the range.
        //   halfLength ... (aquariumWidth - halfLength)
        // where halfLength is half the side-to-side length or width
        // of the object.  We also want some padding on each side, so
        // the actual range is
        //   (halfLength + borderPadding) ...
        //                  (aquariumWidth - halfLength - borderPadding)
        // The size of the range, then, is
        //   aquariumWidth - length - 2 * borderPadding
        int rangeSize = this.width() - objectLength - (2 * borderPadding);
        int x = generator.nextInt(rangeSize);

        // Shift the range right so it starts at halfLength + borderPadding.
        int halfLength = (int)Math.round(objectLength/2.0);
        x += (halfLength + borderPadding);
        return x;
    }

    /**
     *  Determines a valid random y coordinate for the centerpoint of
     *  an object with the given width or height along the y axis.
     *  Precondition: this aquarium must be big enough to accomodate
     *  the object with the given height, plus 10 pixels of padding
     *  above and below.
     **/
    public int randomCenterY(int objectHeight)
    {
        // The entire object should fit within the aquarium, so its
        // center y coordinate should be in the range.
        //   halfHeight ... (aquariumHeight - halfHeight)
        // where halfHeight is half the top-to-bottem width or height
        // of the object.  We also want some padding on each above and
        // below, so the actual range is
        //   (halfHeight + borderPadding) ...
        //                  (aquariumHeight - halfHeight - borderPadding)
        // The size of the range, then, is
        //   aquariumHeight - height - 2 * borderPadding
        int rangeSize = this.height() - objectHeight - (2 * borderPadding);
        int y = generator.nextInt(rangeSize);

        // Shift the range down so it starts at halfHeight + borderPadding.
        int halfHeight = (int)Math.round(objectHeight/2.0);
        y += (halfHeight + borderPadding);
        return y;
    }

}    //end Aquarium class

(AquariumController.java)

/**
 * Aquarium Lab Series: <br>
 * The AquariumController object constructs the aquarium and controls
 * the movement of fish and their display.
 * <br> <br>
 * Created: <br>
 *   23 March 2008, Alyce Brady, from the previous version of AquaSimApplication
 *                               dated 10 July 2002.<br>
 * <br>
 * Modifications: <br>
 *   (date), (your name), Modified to add three fish to the aquarium and
 *                        make them move once. <br>
 * 
 * @author (your name) (with assistance from)
 * @version (date)
 * @see Aquarium
 * @see AquaFish
 * @see AquaSimGUI
 */
public class AquariumController
{
    // instance variables - replace the example below with your own
    private Aquarium aqua;              // reference to the aquarium
    private AquaFish fish1;             // reference to a fish
    private AquaSimGUI userInterface;   // ref. to the graphical user interface

    /**
     * Constructor for objects of class AquariumController
     */
    public AquariumController()
    {
        // Construct the aquarium.  Specify its dimensions when creating it.
        this.aqua = new Aquarium(600, 480);

        // Construct fish and add them to the aquarium.
        this.fish1 = new AquaFish(this.aqua);
        aqua.add(this.fish1);
        //      CODE MISSING HERE!

        // Construct a graphical user interface (GUI) to display the aquarium
        // and interact with the user.  The user interface needs to know about
        // the aquarium, so we pass aqua to the user interface constructor.
        this.userInterface = new AquaSimGUI(this.aqua);

        // Tell the user how to start the program.
        userInterface.println("This will be an aquarium simulation.");
        userInterface.println("Press the Start button to start the simulation.");

    }//end constructor

    /**
     * Runs the aquarium program.
     */
    public void runProgram()
    {
        // First wait for the user to press the start button.
        userInterface.waitForStart();

        // Draw the aquarium and its contents.
        userInterface.showAquarium();

        // Make the fish move and redisplay.
        //      CODE MISSING HERE!

        // Remind user how to quit application.
        userInterface.println ("Close GUI display window to quit.");

    }//end runProgram

}//end AquariumController class

(AquaSimApplication.java)

/** Aquarium Lab Series: <br>    
 *      The AquaSimApplication class contains the main function that will
 *      run the Aquarium Simulation.
 *
 *  @author  Alyce Brady
 *  @version 23 March 2008
 *  @see AquariumController
 **/
public class AquaSimApplication
{
    /**
     *  This is the main function.  It initiates the execution of the program.
     *  @param    String args[] is never used
     **/
    public static void main(String args[])
    {
        // Construct the aquarium controller, which will in turn construct
        // the aquarium, fish, and user interface.
        AquariumController controller = new AquariumController();

        controller.runProgram();

    }//end main

}//end class

(AquaSimGUI.java)

/*
 *  Aquarium Lab Series
 *
 *  Class: AquaSimGUI
 *
 *  License:
 *      This program is free software; you can redistribute it
 *      and/or modify it under the terms of the GNU General Public
 *      License as published by the Free Software Foundation.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 */

import edu.neu.ccs.gui.ActionsPanel;
import edu.neu.ccs.gui.BufferedPanel;
import edu.neu.ccs.gui.Display;
import edu.neu.ccs.gui.DisplayCollection;
import edu.neu.ccs.gui.DisplayPanel;
import edu.neu.ccs.gui.DisplayWrapper;
import edu.neu.ccs.gui.JPTFrame;
import edu.neu.ccs.gui.SimpleAction;
import edu.neu.ccs.gui.TextFieldView;
import edu.neu.ccs.util.JPTUtilities;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.TextArea;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.util.ArrayList;
import javax.swing.Action;

/**
 *  Aquarium Lab Series: <br>
 *  The AquaSimGUI class provides a graphical user interface
 *  to the Aquarium Lab Series.  This class uses the Java
 *  Power Tools (JPT) classes from Northeastern University to
 *  build the graphical interface.  In particular, it inherits
 *  the <code>repaint</code> method (which does not appear in
 *  the specification for this class) from the JPT DisplayPanel
 *  class.  The <code>repaint</code> method draws the
 *  components in the graphical user interface.
 * <br> <br>
 * Created: <br>
 *   10 July 2002,  Alyce Brady<br>
 * <br>
 * Modifications: <br>
 *   22 March 2008, Alyce Brady, Simplified by removing references to
 *                               AquaPoint class and by folding many show
 *                               methods into one that shows an aquarium
 *                               and the fish it contains. <br>
 * 
 *  @author Alyce Brady
 *  @version 22 March 2008
 **/
public class AquaSimGUI extends DisplayPanel
{

    /////////////////////////////////////////////////////////
    // Static Data: Constants not tied to any one instance //
    /////////////////////////////////////////////////////////

    private static final int DEFAULT_FISH = 10;  // default # of fish
    private static final int DEFAULT_STEPS = 15; // # steps to run simulation
    private static final int VIEW_TIME = 1000;  // allow viewer to see display
    private static final int WAIT_TIME = 100;   // between Start button checks


    ////////////////////////
    // Instance Variables //
    ////////////////////////

    private Aquarium aqua = null;             // aquarium in which fish swim
    private AquaView drawingObject = null;    // to draw fish in aquarium
    private int numFish = DEFAULT_FISH;       // number of fish in aquarium
    private int numSteps = DEFAULT_STEPS;     // number of sim. steps to run
//    private Simulation simulation = null;     // controls timesteps
    private boolean started = false;          // has simulation started yet?


    /////////////////////////////////////////////
    // GUI Instance Variables:                 //
    //    Graphical User Interface components  //
    //    for controlling simulation execution //
    /////////////////////////////////////////////

    // Text area in which to display console-type output.
    private TextArea consoleOutput;

    // Display containing the control panel.
    Display controlPanelDisplay;

    // Text field to prompt for number of fish.
    private TextFieldView numFishTF =
        new TextFieldView(
            "" + DEFAULT_FISH,           // initial value displayed in the TFV
            "Number must be positive:",  // prompt for correcting input
            "Incorrect input");          // title for the error dialog box

    // Text field to prompt for number of simulation steps.
    private TextFieldView numStepsTF =
        new TextFieldView(
            "" + DEFAULT_STEPS,          // initial value displayed in the TFV
            "Number must be positive:",  // prompt for correcting input
            "Incorrect input");          // title for the error dialog box

    // Action button to start the simulation and action panel to put it in.
    private SimpleAction start =
        new SimpleAction("Start") {
           public void perform(){ start(); }
        };
    private Action[] startButtonList = {start};
    private ActionsPanel startPanel = new ActionsPanel(startButtonList);

    // Action buttons to execute one step of the simulation and to
    // run the simulation continuously, and action panel to put them in.
/*
    private SimpleAction step =
        new SimpleAction("Single Step") {
           public void perform(){ step(); }
        };
    private SimpleAction run =
        new SimpleAction("Run") {
           public void perform(){ run(); }
        };
    private Action[] runButtonsList = {step, run};
    private ActionsPanel runButtonsPanel = new ActionsPanel(runButtonsList);
*/

    //////////////////
    // Constructors //
    //////////////////

    /** Construct a simple graphical user interface for the Aquarium
     *  Simulation program.
     *      @param  aquarium    the aquarium in which the fish swim
     **/
    public AquaSimGUI(Aquarium aquarium)
    {
        this(aquarium, false, false, false);
    }

    /** Construct a simple graphical user interface for the Aquarium
     *  Simulation program, with or without prompts for the number of
     *  simulation steps.
     *      @param  aquarium    the aquarium in which the fish swim
     *      @param  promptForSimSteps   <code>true</code> if GUI should
     *                                  prompt for number of simulation steps
     **/
    public AquaSimGUI(Aquarium aquarium, boolean promptForSimSteps)
    {
        this(aquarium, promptForSimSteps, false, false);
    }

    /** Construct a graphical user interface for the Aquarium
     *  Simulation program, with or without prompts for the number of
     *  simulation steps and the number of fish.
     *      @param  aquarium    the aquarium in which the fish swim
     *      @param  promptForSimSteps   <code>true</code> if GUI should
     *                                  prompt for number of simulation steps
     *      @param  promptForNumFish    <code>true</code> if GUI should
     *                                  prompt for number of fish
     **/
    public AquaSimGUI(Aquarium aquarium,
                      boolean promptForSimSteps,
                      boolean promptForNumFish)
    {
        this(aquarium, promptForSimSteps, promptForNumFish, false);
    }

    /** Construct a graphical user interface for the Aquarium
     *  Simulation program, with or without prompts for the number of
     *  simulation steps and the number of fish.
     *      @param  aquarium    the aquarium in which the fish swim
     *      @param  promptForSimSteps   <code>true</code> if GUI should
     *                                  prompt for number of simulation steps
     *      @param  promptForNumFish    <code>true</code> if GUI should
     *                                  prompt for number of fish
     *      @param  useSimulationObj    <code>true</code> if GUI should
     *                                  construct and use a Simulation object
     **/
    private AquaSimGUI(Aquarium aquarium,
                      boolean promptForSimSteps,
                      boolean promptForNumFish,
                      boolean useSimulationObj)
    {
        // Save aquarium info. in an instance variable.
        aqua = aquarium;

        // Set layout for entire panel.
        setLayout(new BorderLayout());

        // Create two displays: one in which to view the aquarium
        // and one to contain the control panel.  Add them to the
        // main panel of the GUI.
        add(getViewWindow(), BorderLayout.EAST);
        add(getControlPanel(promptForSimSteps, promptForNumFish,
                            useSimulationObj), 
            BorderLayout.WEST);
        consoleOutput = new TextArea("", 5, 60);
        add(consoleOutput, BorderLayout.SOUTH);

        // Clear window.
        reset();

        // Put the GUI in a window, giving the window a title.
        JPTFrame.createQuickJPTFrame("Aquarium Lab Series", this);

        // Create the Simulation object (if appropriate) and tell the
        // control panel about it.
/*
        if ( useSimulationObj )
        {
            int numFish = getNumberOfFish();
            simulation = new Simulation (aqua, numFish, this);

            // View the initial configuration.
            // Draw the aquarium and fish, redisplay the user interface in the
            // window so that users can see what was drawn.
            show(simulation.getAllFish());
            repaint();
            pauseToView();
        }
 */
    }


    //////////////////////////////////////////////////////////
    // User Interaction Methods (Dealing with controlPanel) //
    //////////////////////////////////////////////////////////

    /**
     *  Wait for start button to be pushed.
     **/
    public void waitForStart()
    {
        while ( ! started )
            JPTUtilities.pauseThread(WAIT_TIME);
    }

    /**
     *  Get the number of fish to put in the aquarium from user input.
     **/
    public int getNumberOfFish()
    {
        waitForStart();
        return numFish;
    }

    /**
     *  Get the number of steps to run from user input.
     **/
    public int getNumberOfSteps()
    {
        waitForStart();
        return numSteps;
    }


    //////////////////////////////////////////////////
    // Method to write text to console-type output. //
    //////////////////////////////////////////////////

    /**
     *  Print the given string to the console-type output window.
     */
    public void print(String s)
    {
        consoleOutput.append(s);
    }

    /**
     *  Print the given string to the console-type output window,
     *  followed by a newline.
     */
    public void println(String s)
    {
        consoleOutput.append(s + "n");
    }


    //////////////////////////////////////////////////
    // Drawing Methods (Delegated to drawingObject) //
    //////////////////////////////////////////////////

    /**
     *  Display the aquarium and its contents: paint the aquarium blue to cover
     *  up old fish, then paint the fish in their current locations.  
     **/
    public void showAquarium()
    {
        drawingObject.showAquarium();
    }

    /**
     *  Pause so user can view the display.
     **/
    private void pauseToView()
    {
        JPTUtilities.pauseThread(VIEW_TIME);
    } 


    ////////////////////////
    // Actions            //
    ////////////////////////

    /** Start the simulation.  (Activated by the start button.)
     **/
    public void start()
    {
        // Get the number of fish and the number of steps.
        numFish = numFishTF.demandInt();
        numSteps = numStepsTF.demandInt();

        // Record that simulation has started and modify what control
        // components are active.
        started = true;
        controlPanelDisplay.setEnabled(false);
//        runButtonsPanel.setEnabled(true);
    }

    /** Execute one step of the simulation.  (Activated by the step button.)
     */
/*
    public void step()
    {
        if ( simulation == null )
            return;

        // Execute a step of the simulation.
        simulation.step();

        // View the new configuration.
        show(simulation.getAllFish());
        repaint();
    }
*/

    /** Start running the simulation.  (Activated by the run button.)
     **/
/*
    public void run()
    {
        if ( simulation == null )
            return;

        Thread myThread = new Thread()
        {
            public void run ()
            {
                runButtonsPanel.setEnabled(false);

                // Move the fish numSteps times.
                for ( int step = 0; step < numSteps; step++ )
                {
                    step();
                    pauseToView();
                }

                runButtonsPanel.setEnabled(true);
            }
        };

        myThread.start();
    }
*/


    //////////////////////////////
    // Private Helper Methods   //
    //////////////////////////////

    /**
     *  Construct and initialize display in which to view aquarium.
     **/
    private Display getViewWindow()
    {
        // Create the panel in which to view the aquarium
        // and disable it (view panel is not interactive).
        // then put it in a display with a title.
        BufferedPanel aquaViewPanel =
            new BufferedPanel(aqua.width(), aqua.height());
        aquaViewPanel.setEnabled(false);

        // Construct an object that knows how to draw the
        // aquarium in the viewing panel (used by other parts
        // of the Aquarium Simulation program as well).
        drawingObject = new AquaView(aquaViewPanel, aqua);

        // Put the view panel in a titled display and return.
        return new Display(aquaViewPanel, null, "Aquarium");
    }

    /**
     *  Construct and initialize display that contains control panel.
     *      @param  promptForSimSteps   <code>true</code> if GUI should
     *                                  prompt for number of simulation steps
     *      @param  promptForNumFish    <code>true</code> if GUI should
     *                                  prompt for number of fish
     *      @param  useSimulationObj    <code>true</code> if GUI should
     *                                  construct and use a Simulation object
     **/
    private Display getControlPanel(boolean promptForSimSteps,
                       boolean promptForNumFish, boolean useSimulationObj)
    {
        DisplayCollection controlPanel = new DisplayCollection();

        // Disable the control panel to start off.
        controlPanel.setEnabled(false);

        // Set up text field views in which to prompt for number
        // of fish and number of simulation steps.
        numFishTF.setPreferredWidth(50);
        numFishTF.getInputProperties().setSuggestion("" + DEFAULT_FISH);
        numStepsTF.setPreferredWidth(50);
        numStepsTF.getInputProperties().setSuggestion("" + DEFAULT_STEPS);

        // Add text field views if appropriate.
        if ( promptForNumFish )
        {
            numFishTF.setEnabled(true);
            controlPanel.add(new DisplayWrapper(
                    new Display(numFishTF, "Number of Fish:", null) ) );
        }
        if ( promptForSimSteps )
        {
            numStepsTF.setEnabled(true);
            controlPanel.add(new DisplayWrapper(
                    new Display(numStepsTF, "Number of Simulation Steps:", 
                                null) ) );
        }

        // Always include start button.
        startPanel.setEnabled(true);
        controlPanel.add(getStartPanel());

        // Add step and run buttons if appropriate.
/*
        if ( useSimulationObj )
        {
            runButtonsPanel.setEnabled(false);
            controlPanel.add(new Display(runButtonsPanel, null, "Run Simulation"));
        }
*/
        // Put the control panel in an untitled display and return.
        this.controlPanelDisplay = new Display(controlPanel, null, null);
        return this.controlPanelDisplay;
    }

    /** Construct action panel for start button (in a separate thread).
     **/
    private Display getStartPanel()
    {
        // Create the Start action panel in a separate thread.
        Thread myThread = new Thread()
        {
            public void run ()
            {
                startPanel = new ActionsPanel(startButtonList);
            }
        };

        // Start parallel thread for start button.
        myThread.start();
        waitForStartPanel();
        return new Display(startPanel, null, null);
    }

    /**
     *  Wait for Start button action panel to be created.
     **/
    private void waitForStartPanel()
    {
        while ( startPanel == null )
            JPTUtilities.pauseThread(WAIT_TIME);
    }


    /** Aquarium Lab Series:
     *  An AquaView object provides a graphical view of fish
     *  in an aquarium.
     *
     *  @author  Alyce Brady
     *  @version 10 July 2002
     *  @see Aquarium
     *  @see BaseFish
     **/
    private class AquaView
    {
        // Encapsulated data
        private BufferedPanel displayPanel;   // where to display
        private Aquarium theAquarium;         // the aquarium to display

        /** Construct an AquaView object to display a particular
         *  aquarium.  
         *      @param panel  the graphical panel in which to display environment
         *      @param a      the aquarium to display
         **/
        public AquaView(BufferedPanel panel, Aquarium a)
        {
            displayPanel = panel;
            theAquarium = a;

            displayPanel.setBackground(theAquarium.color());

        }


        /**
         *  Show the fish in the aquarium.
         *  Paints the aquarium blue to cover up old fish and displays
         *  the fish in the aquarium.
         **/
        public void showAquarium()
        {
            // Redraw the environment to paint over previous positions of fish.
            displayPanel.fillPanel(theAquarium.color());

            // Get graphics context in which everything is displayed.
            Graphics2D drawingSurface = displayPanel.getBufferGraphics();
            drawingSurface.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

            // Draw all of the fish.
            for ( AquaFish fish : theAquarium.getFish() )
            {
                if ( fish != null )
                    drawFish(drawingSurface, fish);
            }

            // Show the redrawn aquarium & fish on the screen.
            repaint();
            pauseToView();
        }


        /**
         *  Helper function that displays a single BaseFish, given
         *  a graphics context.
         *  @param    drawingSurface   context in which to display fish
         *  @param    fish             the fish to be displayed
         **/
        private void drawFish(Graphics2D drawingSurface, AquaFish fish)
        {        
            // Get color of fish.
            drawingSurface.setPaint(fish.color());

            // Get fish size and location from the fish itself.  Find its
            // outline based on the fish size and location.
            double fishLength = fish.length();
            double fishHeight = fish.height();
            double leftEndOfFish = fish.xCoord() - fishLength / 2.0;
            double topOfFish = fish.yCoord() - fishHeight / 2.0;
            double rightEndOfFish = leftEndOfFish + fishLength;
            double bottomOfFish = topOfFish + fishHeight;
            double verticalCenter = fish.yCoord();
            // Fish body parts are drawn to scale.
            double bodyLength = 0.8 * fishLength;
            double leftEndOfBody;        // value depends on fish's direction

            double eyeSize = 0.1 * fishLength;
            double topOfEye = verticalCenter - (0.1 * fishLength)
                              - eyeSize / 2;
            double leftEndOfEye;        // value depends on fish's direction

            double tailLength = 0.25 * fishLength;
            double tailHeightOffset = 0.12 * fishLength;
            double topOfTail = verticalCenter - tailHeightOffset;
            double bottomOfTail = verticalCenter + tailHeightOffset;
            double endOfTail;        // value depends on fish's direction
            double tailMeetsBody;    // value depends on fish's direction

            if (fish.facingRight())    //draw the fish facing right
            {
                leftEndOfBody = rightEndOfFish - bodyLength;
                leftEndOfEye = rightEndOfFish - 0.26 * fishLength;
                endOfTail = leftEndOfFish;
                tailMeetsBody = endOfTail + tailLength;
            }
            else
            {
                leftEndOfBody = leftEndOfFish;
                leftEndOfEye = leftEndOfFish + (0.26 * fishLength)
                                  - eyeSize;
                endOfTail = rightEndOfFish;
                tailMeetsBody = endOfTail - tailLength;
            }

            // Draw the body of the fish as an oval.
            Ellipse2D.Double body
                 = new Ellipse2D.Double(leftEndOfBody, topOfFish,
                     bodyLength, fishHeight);
            drawingSurface.fill(body);

            // Draw the tail as a triangle (filled path with three points).
            GeneralPath tailOutline = new GeneralPath();
            tailOutline.moveTo((float) endOfTail, (float) topOfTail);
            tailOutline.lineTo((float) endOfTail, (float) bottomOfTail);
            tailOutline.lineTo((float) tailMeetsBody, (float) verticalCenter);
            tailOutline.closePath();
            drawingSurface.fill(tailOutline);

            // Draw the eye as a small circle.
            drawingSurface.setPaint(Color.BLACK);
            Ellipse2D.Double eye
                 = new Ellipse2D.Double(leftEndOfEye, topOfEye,
                     eyeSize, eyeSize);
            drawingSurface.fill(eye);
         }

    }

}

(NavigationalAide.java)

import java.awt.Color;
import java.util.Random;


/**
 * Aquarium Lab Series: <br>
 *      The NavigationalAide class defines some of the more complex methods
 *      for keeping track of a fish's size and location in an aquarium.
 * <br> <br>
 * Created: <br>
 *   23 March 2008, Alyce Brady, from the previous version of AquaFish.<br>
 * <br>
 * Modifications: <br>
 *   (date), (your name), Modified to .... <br>
 * 
 * @author (your name) (with assistance from)
 * @version (a version number or a date)
 */
public class NavigationalAide
{
    // STATE

    // Instance Variables: Encapsulated data for EACH fish
    private AquaFish theFish;        // the fish this aide is helping
    private int centerX;             // x-coordinate of fish's centerpoint
    private int centerY;             // y-coordinate of fish's centerpoint
    private boolean facingRight;  // whether fish is facing right or left
    private int length, height; // define size of fish
    private int halfLength, halfHeight; // useful for knowing perimeter of fish

    // OPERATIONS (constructor and methods)

    /**
     *  The NavigationalAide constructor sets properties of the fish.
     *  Precondition: the aquarium must be big enough to accomodate
     *  the biggest fish (currently 75 pixels long and 30 pixels high)
     *  plus 10 pixels of padding in all four directions.
     *  @param    fish   the fish whose size and location this aide is
     *                      keeping track of
     **/
    public NavigationalAide(AquaFish fish)
    {
        // Keep track of which fish we are dealing with.
        theFish = fish;

        // Initialize size, position, and direction.
        initSize();
        initPos();
        facingRight = true;
    }

    /**
     *  Initializes fish size:
     *  This helper function determines the height and length of the fish.
     *  Fish are evenly distributed among 4 different sizes based on their 
     *  ID numbers.
     **/
    private void initSize()
    {
        // Possible fish lengths are: ?, ?, ?, and ?.
        // The height of a fish is always 40% of its length.
        length = 30 + (theFish.id() % 4) * 15;
        height = (int)Math.round(0.4*length);

        // The halfLength and halfHeight instance variables are useful to
        // determine the left, right, top, and bottom edges of the fish,
        // starting from the centerpoint indicated by (centerX, centerY).
        halfLength = (int)Math.round(length/2.0);
        halfHeight = (int)Math.round(height/2.0);
    }

    /**
     *  Initializes fish position and direction.
     *  This helper function assigns coordinates to a fish such that the
     *  fish is placed within the bounds of the Aquarium.
     *  Precondition: the aquarium must be big enough to accomodate
     *  the biggest fish (currently 75 pixels long and 30 pixels high)
     *  plus 10 pixels of padding in all four directions.
     **/
    private void initPos()
    {
        // Initialize my position and direction.
        centerX = theFish.aquarium().randomCenterX(length);
        centerY = theFish.aquarium().randomCenterY(height);
    }

    /**
     *  Gets the x coordinate in the aquarium of the fish's centerpoint.
     *  @return    the x coordinate of the fish's centerpoint
     **/
    public int centerpointX()
    {
        return centerX;
    }

    /**
     *  Gets the y coordinate in the aquarium of the fish's centerpoint.
     *  @return    the y coordinate of the fish's centerpoint
     **/
    public int centerpointY()
    {
        return centerY;
    }

    /**
     *  Determines whether the fish is facing right.
     *  @return     <code>true</code> if fish is facing right;
     *              <code>false</code> otherwise
     **/
    public boolean isFishFacingRight()
    {
        return facingRight;
    }

    /** Gets the length of the fish.
     *  @return   fish length
     **/
    public int fishLength()
    {
        return length;
    }

    /** Gets the height of the fish.
     *  @return    fish height
     **/
    public int fishHeight()
    {
        return height;
    }

    /** Gets half the length of the fish.
     *  @return    half the fish length (rounded if necessary)
     **/
    public int halfFishLength()
    {
        return halfLength;
    }

    /** Gets half the height of the fish.
     *  @return    half the fish height (rounded if necessary)
     **/
    public int halfFishHeight()
    {
        return halfHeight;
    }

    /**
     *  Compute how far the fish is from the wall in front of it.
     *  @returns    distance from front of fish to facing wall
     **/
    protected int fishDistanceToWall()
    {
        int leftEdgeOfFish = centerX - (halfLength + 1);
        int rightEdgeOfFish = centerX + (halfLength + 1);
        if ( isFishFacingRight() )
            return (theFish.aquarium().width() - rightEdgeOfFish);
        else
            return leftEdgeOfFish;    // since left edge of aquarium is 0
    }

    /**
     *  Determine whether the fish is at the surface.
     *  A fish is considered at the surface if it cannot ascend; in other
     *  words, if the distance from the center of the fish to the surface
     *  is less than the fish's height.
     *  @returns    <code>true</code> if fish is at the surface;
     *              <code>false</code> otherwise
     **/
    public boolean fishAtSurface()
    {
        int topOfFish = centerY - (halfHeight + 1);
        return (topOfFish <= height);
    }

    /**
     *  Determine whether the fish is at the bottom.
     *  A fish is considered at the bottom if it cannot descend; in other
     *  words, if the distance from the center of the fish to the bottom
     *  is less than the fish's height.
     *  @returns    <code>true</code> if fish is at the bottom;
     *              <code>false</code> otherwise
     **/
    public boolean fishAtBottom()
    {
        int bottomOfFish = centerY + (halfHeight + 1);
        return (bottomOfFish >= (theFish.aquarium().height() - height));
    }

    /**
     *  This function is provided primarily for debugging purposes.
     *  @return    a string representation of a fish
     **/
    public String toString()
    {
        String dir = "L";
        if ( isFishFacingRight() )
            dir = "R";
        return " (" + centerX + ", " + centerY + ") " + dir + " ";
    }

    /**
     *  Reverses direction.
     **/
    protected void reverseFishDir()
    {
        facingRight = ! facingRight;
    }

    /** Moves the fish <code>distance</code> units to the right.
     *  @param  distance   distance to move right
     **/
    protected void moveFishRight(int distance)
    {
        centerX += distance;
    }

    /** Moves the fish <code>distance</code> units to the left.
     *  @param  distance   distance to move left
     **/
    protected void moveFishLeft(int distance)
    {
        centerX -= distance;
    }

    /** Moves the fish <code>distance</code> units up.
     *  @param  distance   distance to move up
     **/
    protected void raiseFish(int distance)
    {
        centerY -= distance;        // y coordinates get smaller going up
    }

    /** Moves the fish <code>distance</code> units down.
     *  @param  distance   distance to move down
     **/
    protected void sinkFish(int distance)
    {
        centerY += distance;        // y coordinates get bigger going down
    }

}

not hesitate to tell you all that i am actually a java dumb.
i am stress and i need 2 pass up in 1 week times.
this is my final year last subject paper project question.
i got no one can ask and help me solve this problem.
hope u guys will helps.

First, use code tags when you post code, I am not even going to attempt to read any of that.

For two, all you've done is block copy your assignment. We are not a homework service, and are not going to do it for you. You even asking is against the terms and conditions that you agreed to when you signed up here.

If that is what you want then go to
http://www.rentacoder.com/

Of course, but we need more info (as my first reply, sarcastically, implied). Post all error/compiler messages, post your code, and post what the program produces and what it is suppossed to produce.

As masijade said, you failed to tell us what errors do you get. You are not going to correct you entire project. That is your teacher job.
What errors do you get?
Where?
State specific lines, error messages!
What it does and what it is supposed to do?

We do not spend our lives by fixing other people's problems for free. Why should we bother to read and understand this mess when you are not making an effort to explain anything

Also:

You can obtain these
classes from your lecturer.

If I assume correctly, you were given these classes by your teacher. Your job was to understand them. Then it would be easy to complete the project. All you did was post some code without explaining which part doesn't work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.