Any pro can help me see what mistake i did? ( Your Own Droid)


#1
public class Droid {
  int batteryLevel;
  public Droid() {
    batteryLevel = 100;
  }
  // Your own Droid
  public int activate() {
    System.out.println("Activated. How can I help you?");
    batteryLevel = batteryLevel - 5;
    System.out.println("Battery level is: " + batteryLevel + " percent.");
  }  
  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.");
    }
  }  
  public int checkBatteryLevel() {
    System.out.println("Battery level is: " + batteryLevel + " percent.");
    return batteryLevel;
  }
  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.");
    }
  }
  public static void main(String[] args) {
    Droid bee = new Droid();
    bee.activate();
    bee.chargeBattery(5);
    bee.hover(2);
  }
}

System keep show out:

Droid.java:11: error: missing return statement
}
^
Droid.java:20: error: missing return statement
}
^
Droid.java:33: error: missing return statement
}
^
3 errors


Any pro can help me see what mistake i did?
Million thanks for help.This text will be blurred


#2

here:

 public int activate()

the int keyword indicate that your method returns an integer, which is not happening, so Java throws an error


#3

Thanks for your remind.


#4

Do you know how to solve this problem now you know what the problem is?


#5

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