Incompatible types


#1




Droid.java:32: error: incompatible types: unexpected return value
return batteryLevel;
^
Droid.java:39: error: incompatible types: unexpected return value
return batteryLevel;
^
Droid.java:62: error: incompatible types: unexpected return value
return batteryLevel = batteryLevel - 20;
^
3 errors


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;
  
  if (batteryLevel >= 100){
    
    return batteryLevel;
  
    System.out.println("Battery level is " + batteryLevel + "percent.");
  
  }
 else {
   
   return batteryLevel;
   
 System.out.println("Battery level is: " + batteryLevel );
   
    }
}    
  public int checkBatteryLevel(){
    
    System.out.println("Battery level is: " + batteryLevel + "percent.");
    
    
  }
   
 public void hover (int feet){
   
   if (feet >= 2){
     
     System.out.println("Error! I cannot hover above 2 feet!");
     
   }
 
  else{
    
    return batteryLevel = batteryLevel - 20;
  }
    System.out.println("Hovering...");
      
    
    
    System.out.println ("Battery level: " + batteryLevel + "percent.");
      
  
 }   
 public static void main(String[] args){
   
   Droid myDroid = new Droid();
   myDroid.activate();
   myDroid.chargeBattery(8);
   myDroid.hover(1);
   
 }
 }


#2

Hi, I Know what the issue is.

Take a look at your code. It seems that you have mentioned void in a method.

for example if u say

public void dog(){
return "Woof!";
}

That is wrong because you previously told java by stating "void" that the method doesn't actually return anything.
Get rid of void and replace it with the data type you wanna return.

  • PythonMaster

#3

I actually figured it out. Thanks though!

Best,
Seth Niden-Preis


#4

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