Missing return statements?


#1



https://www.codecademy.com/courses/learn-java/projects/droid


Droid.java:29: error: missing return statement
}
^
Droid.java:47: error: missing return statement
}
^
2 errors


DONT KNOW WHY THIS KEEPS HAPPENING. HERE IS THE 2 SETS OF CODE. 

public int chargeBattery(int hours){
  System.out.println("Droid charging...");
    batteryLevel = batteryLevel + hours;
  
  if (batteryLevel >= 100){ 
  System.out.println("Battery level is :" + batteryLevel + "percent.");
 
} 
  else {
    System.out.println("Battery level is:" + batteryLevel + "percent.");
  
  }
}  



AND


public int hover(int feet){
 if (feet > 2){
  System.out.println("Error! I cannot hover above 2 feet.");
 }
  else{
      System.out.println("Hovering...");
      batteryLevel = batteryLevel - 20;
    
      System.out.println("Battery level is:" + batteryLevel + "percent.");
    
    }
}


ALL IF STATEMENTS are showing the errors .Thank you.


#2

If you make int methods (like you've done here), you are required to return an int. This appears to be unnecessary in this case, since you are just printing text, so instead change public int to public void. Void statements don't require you to return anything.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.