Can't debug final error on Your Own Droid exercise


#1

//darn thing doens't work right now
public class Droid {
  int batterLevel;
  public Droid () {
   batteryLevel = 100;
  }
   public void activate() {
      System.out.println("Boot complete. Awaiting command");
      batteryLevel = batteryLevel -5;
      System.out.println("Battery at: " + batteryLevel + " percent.");
    }
      public void chargeBattery(int hours) {
        System.out.println("Charging...");
        batteryLevel = batteryLevel + hours; 
        if (batteryLevel > 100) {
          batteryLevlel = 100;
          System.out.println("Battery at: " + batteryLevel + " percent.");
        }
        else {
          System.out.println("Battery at: " + batteryLevel + "percent.");
        }
      }
      public int checkBatteryLevel() {
        System.out.println("Battery at: " + batteryLevel + "percent.");
        return batteryLevel;
    }
      public void hover(int feet) {
        if (feet > 2) {
          System.out.println("Exceeding maximum altitude.");
        }
        else {
          System.out.println("Yeah, I can fly.");
          batteryLevel = batteryLevel - 20;
          System.out.println("Battery at: " + batteryLevel + "percent.");
      }  
      }
      public static void main(String [] args) {
        Droid myDroid = new Droid();
          myDroid.activate();
          myDroid.chargeBattery(5);
          myDroid.hover(3);
        }
      }
}

I started out with a whole mess of errors and have been using previous forum posts to help me debug, but I'm stuck.

Left with this error:

Droid.java:44: error: class, interface, or enum expected
}
^
1 error


#2

I will post an anwser soon!


#3

Hey its just two types @mcavanah86! First one!:

Its suppose to be batteryLevel.

Next one:

I put it in bold, its suppoose to be battery level. Hope this helped! :smile:


#4

Fixed those, but I'm still getting the same error :confused:


#5

can you post your updated code here pls? Thankyou


#6

//darn thing doens't work right now
public class Droid {
  int batteryLevel;
  public Droid () {
   batteryLevel = 100;
  }
   public void activate() {
      System.out.println("Boot complete. Awaiting command");
      batteryLevel = batteryLevel -5;
      System.out.println("Battery at: " + batteryLevel + " percent.");
    }
      public void chargeBattery(int hours) {
        System.out.println("Charging...");
        batteryLevel = batteryLevel + hours; 
        if (batteryLevel > 100) {
          batteryLevel = 100;
          System.out.println("Battery at: " + batteryLevel + " percent.");
        }
        else {
          System.out.println("Battery at: " + batteryLevel + "percent.");
        }
      }
      public int checkBatteryLevel() {
        System.out.println("Battery at: " + batteryLevel + "percent.");
        return batteryLevel;
    }
      public void hover(int feet) {
        if (feet > 2) {
          System.out.println("Exceeding maximum altitude.");
        }
        else {
          System.out.println("Yeah, I can fly.");
          batteryLevel = batteryLevel - 20;
          System.out.println("Battery at: " + batteryLevel + "percent.");
      }  
      }
      public static void main(String[] args) {
        Droid myDroid = new Droid();
          myDroid.activate();
          myDroid.chargeBattery(5);
          myDroid.hover(3);
        }
      }
}

#7

Can you try not initalizing it in your constructor and initalizing it globaly?

What i mean in code is instead of this:

Do this:

public class Droid {
  int batteryLevel = 100;
  public Droid () {
   
  }

#8

No dice. Still getting the same error.


#9

What does the error say now?


#10

Droid.java:44: error: class, interface, or enum expected
}
^
1 error


#11

Delete your last bracket :smile: wow how come i didnt notice that.


#12

Thanks! I had collapsed brackets to see if I was missing one or had an extra but it seemed to be fine.