Your own Droid


#1

Heya, can you please help me here. I cannot find out why its not working,.

public 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("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 int checkBatteryLevel () {
  System.out.println("Battery level is: " +batteryLevel + "percent");
  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 + "percent");
   }
  }

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

#2

Hey @zyndria! You have three errors. Nothing to worry about :smile:

First Error

you forgot to open the bracket of your main.

Second Error:

Mispeled sample when you where creating a new instance

Third:

You forgot to close your whole class;

Hope this helped!

So at the end of code just add a bracket!


#3

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