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 6 of 6

Thread: Buej programming issue

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Buej programming issue

    Hi there i am relativity new to java programming and i am having trouble with creating a code which increases the fish's length by 1% of the amount of food eaten?

    Here is the code:

    public class Fish
      {
        private String name;
        private int age;
        private double length;
        private String species;
        private double temperature;
        private boolean isFemale;
        private double numEggs;
     
     
     
    /**
         * Constructor for objects of class Fish
         */
            public Fish(String newName)
           {
            name = newName;
            age = 1; // takes about 1 week to hatch from an egg
            length = 10; // slightly small
            species = "Clownfish";
            temperature = 27; // ideal body temperature for a fish
            isFemale = true;
            numEggs = 0;
            }
     
         /**
         * The fish grows by 1% of the amount of pellets eaten
         */
            public void eatFood (int pellets)
           {
            length=(length+pellets);
            System.out.println(length + " " + "cm's");
            }
    }

    Thanks
    Last edited by BeardedAxeWound; August 8th, 2012 at 05:31 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Buej programming issue

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Can you write an algebraic equation for how the value of the length should change?

    Do you know that 1% = .01 or 1/100
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Buej programming issue

    Hey Norm, i am unsure of what to exactly write for that method therefore the method which i have written there is incorrect.

    So i was wondering what exactly I would have to write to achieve the correct method.

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Buej programming issue

    As norm said 1% = 0.01 = 1/100,so you should add to length of the fish the (amount of pellets)*(1/100),if having problem post back

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Buej programming issue

    Thank you very much it finally works
    Last edited by BeardedAxeWound; August 8th, 2012 at 05:52 PM.

  6. #6
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Buej programming issue

    The goal is to increase the length of the fish by (1%)*(pellets) -correct me if i am wrong.
    For instance you have a really big fish,that in a meal ate 200 pellets.Before meal fish's length was 10 m.Now it ate 200 pellets,so it has to grow up.How much?It's previous length plus the length it gained while eating.
    Your code
    length = (pellets) *(1/100);
    is translated into this --> New length of the fish = the length it gained while eating.
    Why is this false?Because you take into no consider the length that the fish had before the meal.So give it another shot

    As for the newbie,no problem

Similar Threads

  1. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  2. A GUI issue.
    By LasOz in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 9th, 2012, 12:46 AM
  3. Replies: 0
    Last Post: December 12th, 2011, 03:17 PM
  4. not sure what the issue is here
    By Tfence in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 28th, 2011, 02:18 AM
  5. i do not know how to solve this issue
    By javastupi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 20th, 2010, 08:28 PM