public static double changeToSpeed(String time, int distance)
{
if(time.indexOf(":") == 1){
int minutes = time.charAt(0);
String sec = time.substring(3, 7);
double seconds = Double.parseDouble(sec);
double totalTime = 60 * minutes + seconds;
double endSpeed = distance / totalTime;
return endSpeed;
}
else if(time.indexOf(":") == 2){
String min = time.substring(0, 2);
String sec = time.substring(3, 7);
double minutes = Double.parseDouble(min);
double seconds = Double.parseDouble(sec);
double totalTime = 60 * minutes + seconds;
double endSpeed = distance / totalTime;
return endSpeed;
}
else if(time.indexOf(":") == -1){
int minutes = 0;
double seconds = Double.parseDouble(time);
double totalTime = 60 * minutes + seconds;
double endSpeed = distance / totalTime;
return endSpeed;
}
}
I'm trying to get different returns based on where the ":" is in the String time. This gives me a problem with having no return value in the main part of the method, but when i do that it gives me a different error saying I have too many return statements. I needs the helps.