Having trouble with Droid Robot Code


#1

I cant seem to figure out what the problem with my code is. Sorry I am a beginner and still need to figure out how to debug code properly.

The error I get is "Reached end of file while parsing }"

Here is my code.
public class Droid {
int batterylevel;
public Droid() {
batteryLevel = 100;
}

public void activate() {
System.out.println("Activated. How May 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(batteryLevel >= 100) {
batteryLevel = 100;
System.out.println("Battery level is " + batteryLevel);
}
else {
System.out.println("Battery level is " + batteryLevel);
}
}

public int checkBatteryLevel() {
System.out.println("Battery level is " + batteryLevel);
return batteryLevel;
}

public void 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);
}
}

public static void main(String[] args) {
Droid myDroid = new Droid();
myDroid.activate();
myDroid.chargeBattery(5);
myDroid.hover(5);
}


#2

Hey @devblaster06829,
Ok, one thing I noticed when I ran your code through Eclipse was that you need to change your variable name when you declare it from batterylevel to batteryLevel, as it's a different name to every other time you use it.
Also, your error is because you don't have enough curly brackets. Just put another closing curly bracket at the end of your code, as you need to close your class.

If this solves your question, please be so kind as to mark this as the solution :slight_smile: