Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Bluej fish project

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    Auckland New Zealand
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Bluej fish project

    I have three assignments using bluej program im a learner at it i have done he first two assignment but the last one is causing me grief to no better end i have hopefully attached the file with this message.

    The question i need to know is

    This in only in the Tank Class

    Task A
    1 i can only at the moment have one fish in the tank i need to increase the amount of fish in the tank.
    2 be able to ad a fish to the Tank.
    3 Remove a fish from the Tank.
    4 Have a method to get the population of the Tank.

    Task B
    1 In my getFish method i Need to change method so that it returns a fish based on an index passed in.
    2 In my hasFish method i need method to return true value if is a fish in the tank.
    3 In my printTank method in this method, change the method so that it prints out the number of fish in the tank and print out the list of the fish in the tank.
    4 In my feed method in this method the fish that gets fed is determined randomly.

    if cannot down load file here is the code

    /**
     *  
     * Charlie Ngatai
     * @v3 
     */
     
    import java.util.ArrayList;
     
    public class Tank
    {
        private Fish myFish;
        private Feeder feeder;
        private boolean full;
        private boolean hasFeeder;
     
        /**
         * Constructor for objects of class Tank
         */
        public Tank()
        {
            full = false;
            hasFeeder = false;
            myFish = null;
            feeder = null;
        }
     
        /**
         *  Add a fish to the Tank.
         *  @param fish, the fish to the tank
         */    
        public void addFish(Fish fish)
        {
            // Can only have one fish
            if(!full)
            {
                myFish = fish; 
                full = false;
            }
            else
            {
                System.out.println("Sorry there is no room in the tank. It is already occupied and the resident fish will not share. ");
            }  
        }
     
        /**
         * Remove the fish - eg if it has died.
         */        
        public void removeFish()
        {
            // Can only remove if there is a fish there
            if(full)
            {
                myFish = null;
                full = false;
            }
        }
     
        /**
         * Returns the tank's fish (which may be null).
         * @return The fish that lives in the tank
         */        
        public Fish getFish()
        {
            return myFish;
        }
     
        /**
         * Returns True if a fish is living in the tank. False if the tank is empty.
         * @return the emptiness of the tank. 
         */        
        public boolean hasFish()
        {
            return full;
        }
     
        /**
         * Prints information about this tank and any fish living in it.
         */
        public void printTank()
        {
            System.out.println("************************");
            System.out.println("Welcome to my Tank");
            if(full)
            {
                System.out.println("There is a fish living in it.");
                System.out.println(myFish.toString());
            }
            else
            {
                System.out.println("The tank is currently empty");
            }
        }
     
        /**
         * Method to attach a new feeder to the Tank
         * @param newFeeder
         */
        public void addFeeder(Feeder newFeeder)
        {
            if(!hasFeeder)
                feeder = newFeeder;
        }
     
        /**
         * Allows the feeder to be removed
         */
        public void removeFeeder()
        {
            // Can only remove if there is a feeder there
            if(hasFeeder)
            {
                feeder = null;
                hasFeeder = false;
            }
        }
     
        /**
         * Method to restock the feeder
         * @param amount - int
         * @param food - food
         */
        public void restock(int amount, String food)
        {
            if (food.equals("Fish food pellets")||
                food.equals("Spirulina pellets")||
                food.equals("Brine Shrimp")||
                food.equals("Whole wheat flake"))
            {
                feeder.changeFoodLevel(amount);
                feeder.setFoodType(food);
            }
        }
     
        /**
         * Feeds the fish in the tank. 
         */
        public void feed()
        {
            int flare = feeder.getFlare();
            feeder.changeFoodLevel(-flare);
            myFish.eat(flare);
        }
     
        /**
         * Simulates the passing week 
         */
        public void simulateWeeks(int weeks)
        {
            for (int week = 1; week < weeks; week++)
            {
                for(int day = 1; day < 7; day++)
                {
                    System.out.println("The fish has been fed.");
                    feed();
                    System.out.println("The fish has swam 50 m.");
                    myFish.swim(50);
                }
                System.out.println("The fish has a birthday.");
                myFish.birthday();
            }
        }
    }
    Any help much appreciated thankyou from me IN NZ
    Attached Files Attached Files
    Last edited by charliengatai4381; February 28th, 2014 at 06:26 PM. Reason: need to add tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Bluej fish project

    Please post the code you have questions about here on the forum.
    Be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Location
    Auckland New Zealand
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej fish project

    Sorry Im new to using this web site i have posted the code on the same page thankyou.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Bluej fish project

    You left off the code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Location
    Auckland New Zealand
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Re: Bluej fish project

    Thankyou very mcu learnt something new.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Bluej fish project

    Can you explain what problems you are having?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Location
    Auckland New Zealand
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bluej fish project

    Every time i add something to the program i run into trouble with compiling and my note are not helping just need some advice on the best way to tackle it.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Bluej fish project

    best way to tackle it.
    Read the error message, find the API doc for the exception(they are all classes), post the full text of the error message here and ask about it.

    It takes time to get familiar with the common errors.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. BlueJ program !
    By fevdjyg in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 16th, 2013, 04:35 PM
  2. BLUEJ Program Help
    By threlot in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 5th, 2013, 09:42 PM
  3. Bluej help
    By kiara4 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 13th, 2012, 05:29 PM
  4. Bluej issue
    By BeardedAxeWound in forum Object Oriented Programming
    Replies: 16
    Last Post: August 26th, 2012, 03:07 AM