For my following function I get the error message: This method must return a result of type double
But my output is a double. Where is my error?
if (currentAgent == Halteteil && predecessor == Oberteil) {
return 40.4;
} else if (currentAgent == Oberteil && predecessor == Ring) {
return 13.5;
}
Haltetil, Oberteil and Ring are my Agents. The Output is the delaytime for my service Block
CodePudding user response:
There is a possibility that neither condition is triggered. Java "sees" that and tells you via the error. You must provide a "fallback" as below:
if (currentAgent == Halteteil && predecessor == Oberteil) {
return 40.4;
} else if (currentAgent == Oberteil && predecessor == Ring) {
return 13.5;
}
return 0.;
If you like, you can "catch" that via an error msg or by returning -infinity
but you have to give Java the ability to always return a double