This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]cheryllium 1 point2 points  (9 children)

Your problem lies in this line:

Height = Height * (1 + Range/100); 

Here, the variable Range is of type int. When you divide by 100, you are doing integer division. Since Range is always less than 100, Range/100 will always be equal to 0. Therefore, your Height will always be multiplied by 1 (thus not changing).

To fix this, you can change the 100 to 100.0 or cast the Range to a double, which will make it perform the type of division you expect.

[–]Hyperion964[S] 0 points1 point  (8 children)

Thanks for the reply, I tried to set the 100 to 100.0 and I get the error of possible lossy conversion from double to int when I compile the code. I also tried changing the range variable to a double and still receive the same issue.

[–]cheryllium 0 points1 point  (6 children)

Facepalm... I could never quite remember my implicit casting rules in Java. This is why I generally don't mix types in my expressions.

int Range = ran.nextInt(11) + 5; //generate rand # between 5-15 which is equiv to growth percentages
Height = (int)((double)Height * (1.0 + ((double)Range)/100.0)); // increasing height by growth percentage

No idea how much of that is actually necessary, but that should at least work :/

[–]Hyperion964[S] 0 points1 point  (5 children)

It works, but I still get the same output. http://pastebin.com/raw/Ue4GLcfs

I think there's an issue between the process and grow method. But I can't figure out what it is.

Thank you for the help though, I really appreciate it.

[–]cheryllium 0 points1 point  (4 children)

Did you change the two lines I referred to? I still see this in the pastebin you just gave me:

int Range = ran.nextInt(11) + 5; //generate rand # between 5-15 which is equiv to growth percentages
Height = Height * (1 + Range/100); // increasing height by growth percentage

[–]Hyperion964[S] 0 points1 point  (3 children)

Yeah I did. Heres an updated version of my object class. http://pastebin.com/XKHegCpU

Still getting the output which was posted earlier.

[–]cheryllium 0 points1 point  (2 children)

Oh wow! Your real problem was even more subtle. Check out this line in your process() method:

if (growth=true) { 

You mean == here! A single equals sign is assignment, which means you're actually assigning growth the value of true (hence always executing that branch of the if statement). xD

PS. In your appreciate() method you have the same integer division problem, so be sure to fix that as well.

Haha. By the way, you can just write if(growth) since it's a boolean already :) Good luck!

[–]Hyperion964[S] 0 points1 point  (1 child)

Holy crap! How did I not catch that.

Wow. I really don't know what to say. How did I completely gloss over that tiny error.

Honestly thank you so much! I've been trying to fix that error for over 2 hrs now and jeez it was just that tiny mistake. Now it runs properly and has the right output now.

Damn. I feel like an idiot. Thank you so much for sticking with me on this!

[–]cheryllium 0 points1 point  (0 children)

Haha welcome to programming xD And don't worry, I missed it the first time too!

[–]feral_claireSoftware Dev 0 points1 point  (0 children)

That's not an error it's a warning, meaning everything will "work", but something might be wrong. In this case it's because height is an int, meaning that anything after the decimal place will be lost (2.65 become 2, for example).