My code is below... when I compile, it gives me a "Missing Return Statement" on my middle method. I realize that it's due to it being Double instead of Static... I don't fully understand Method openings and their impact. This is like my first week of playing with Java. :-/
I am bolding the method that is throwing the compilation error.
As you remember, a method heading has several parts (you can find full details in the Java Language Specification but it's not easy to read):
Access modifier (optional): private, public or protected.
Other modifiers (optional), eg static final, synchronized.
Generic formal type parameter (optional) eg <T>, and I think that comes here rather than later.
return type (compulsory). If the method returns nothing, write void instead of the return type.
method identifier (compulsory)
List of parameters, separated by commas. A zero-length list is permitted
In the example you quoted, the method declares a return type of "double." This tells the compiler that a double value will come back when that method completes. You should be able to write
double sum = getSum(numbers);
So the compiler goes through every method and looks whether it returns what it claims to, from every possible "path" through the method.
Your method claims to return a double, but doesn't return a double. It actually behaves as a method which doesn't return anything (see above). It also has the peculiarity that it claims to take a double as a parameter, but it doesn't do anything with that parameter. It calculates and prints the total of an int. So you have an unused parameter; that ought to be deleted.
Joined: Oct 13, 2005
Please use the code button; I have edited your post so you can see how much better it looks.
You can find the Java Language Specification section here, but it is by no means easy to read.
Joined: Feb 21, 2009
Thank you so very much!
Be warned that I will be back with many many questions .