# Buej programming issue

• August 8th, 2012, 05:10 PM
BeardedAxeWound
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:

Code java:

```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 :)
• August 8th, 2012, 05:18 PM
Norm
Re: Buej programming issue
[code=java]
[/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
• August 8th, 2012, 05:35 PM
BeardedAxeWound
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.
• August 8th, 2012, 05:37 PM
Samaras
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 :)
• August 8th, 2012, 05:47 PM
BeardedAxeWound
Re: Buej programming issue
Thank you very much it finally works :)
• August 8th, 2012, 05:54 PM
Samaras
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.
`length = (pellets) *(1/100);`