Trying to find out what am I doing wrong, plz help Droid project

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
Please help me out… can’t figure out how to get this to work…

<In what way does your code behave incorrectly? Include ALL error messages.>
Droid.java:37: error: missing return statement
}
^
1 error



public class Droid {
  
  int batteryLevel;
  
  public Droid() {
    batteryLevel = 100;
  }
  
  public void activate() {
    System.out.println("Activated. How can I help you?");
    batteryLevel = batteryLevel - 5;
    System.out.println("Battery level is: " + batteryLevel + " percent.");
  }
  public void chargeBattery(int hours) {
    System.out.println("Droid charging");
    batteryLevel = batteryLevel + hours;
    if (100 > batteryLevel) {
      batteryLevel = 100;
        System.out.println("Battery level is: " + batteryLevel + " percent.");
    } else {
      System.out.println("Battery level is: " + batteryLevel + " percent.");
    }
  }
  public int checkBatterLevel() {
    System.out.println("Battery level is: " + batteryLevel + " percent.");
    return batteryLevel;
  }
  public int hover(int feet) {
    if (2 > feet) {
      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.");
      return batteryLevel;
    }
  }
  public static void main(String[] args) {
    Droid m10 = new Droid();
    m10.activate();
    m10.chargeBattery(5);
    m10.hover(2);
}
}


It seems to suggest that there should be another return statement. Is there a problem in adding it?

Thank you, I just had to look closer at the return statement issue, I had to change the method to void to fix the problem. Got me thinking thank you.

1 Like

Actually, not quite. You just forgot to return for all cases of the conditional. The first case, if true, caused the entire method to lack a return value. Take a third look!

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