Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

I'm kinda stuck with my school project http://i.imgur.com/XI3zw.png that's the code everything was provided by my instructor, i just added return size>0 but it wants me to remove the exception. If i put the return statement below the exception, it wants me to remove the return statement Can anyone tell me what is wrong?

OpenStudy (espex):

Is the closing brace below your exception line?

OpenStudy (anonymous):

yeah

OpenStudy (espex):

size looks like a keyword, do you have that assigned to anything?

OpenStudy (anonymous):

@eSpeX will give u the answer..

OpenStudy (anonymous):

I have this http://i.imgur.com/uzd3x.png also the error says Unreachable code..

OpenStudy (espex):

It is unusual that you have the return statement like that, why would you not be doing: return size;

OpenStudy (espex):

Once you have issued a return the code beneath it is unreachable, also unnecessary so you should comment it out.

OpenStudy (anonymous):

this program is like a simulation of fish eating other fish and size gets bigger that method check for if size is greater than 0 which means the fish is not dead. I could comment out the throw exception part but I don't know why if it's there in the first place if boolean returns something it ends the method..I guess ill ask my instructor thanks for the help :)

OpenStudy (espex):

The exception is there to ensure you code something, it helps you avoid turning in a program with a missing portion.

OpenStudy (espex):

I see, you are returning whether the condition is true/false.

OpenStudy (anonymous):

oh I see..lol I was wondering why there were this same exception in every method in the class

OpenStudy (espex):

With those in place the program should die each time one of those methods are hit.

OpenStudy (espex):

Go through and comment all those out and see if it still gives you errors.. :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!