My Droid Challenge help


#1

Here is my code:
public class Droid{

private int batteryLevel = 100;

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

Droid myDroid = new Droid ();
myDroid.activate;
myDroid.chargeBattery(5);
myDroid.hover(feet);

}

and I'm getting these errors:
Droid.java:39: error: expected
myDroid.activate;
^
Droid.java:40: error: expected
myDroid.chargeBattery(5);
^
Droid.java:40: error: illegal start of type
myDroid.chargeBattery(5);
^
Droid.java:41: error: expected
myDroid.hover(feet);
^
Droid.java:41: error: expected
myDroid.hover(feet);
^
5 errors

I really don't know where I went wrong....


#2

The error could be due to the white space before the ().

Does this look right (not the error, however)?


#3

Ha thanks for pointing out the typo. But the whitespace didn't fix the problem :pensive:


#4

The problem is with myDroid.activate; You are missing () before the semi-colon. That is why the java compiler is raising errors from that line onwards.


#5

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