Droid problem


#1



https://www.codecademy.com/courses/learn-java/projects/droid


I've looked through the errors and there seems to be something wrong with checkBatteryLevel and my hover method.
I have no idea why my main isn't working.


public class Droid {
    public int batteryLevel;
    public void 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);
  }
  public void chargeBattery (int hours) {
    System.out.println("Droid charging...");
    batteryLevel = batteryLevel + hours;
    if (batteryLevel > 100){
      System.out.println("Battery level is:" + batteryLevel + " .");
    }else{
      System.out.println("Battery level is:" + batteryLevel + " .");
    }
      public int checkBatteryLevel ()
      {
    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 droid = new Droid();
     droid.activate();
     droid.chargeBattery(5);
     droid.hover(1);
  } 
 }
//Errors
Droid.java:19: error: illegal start of expression
      public int checkBatteryLevel ()
      ^
Droid.java:19: error: ';' expected
      public int checkBatteryLevel ()
                                  ^
Droid.java:23: error: illegal start of expression
  public void hover(int feet){
  ^
Droid.java:23: error: illegal start of expression
  public void hover(int feet){
         ^
Droid.java:23: error: ';' expected
  public void hover(int feet){
                   ^
Droid.java:23: error: ';' expected
  public void hover(int feet){
                            ^
Droid.java:35: error: illegal start of expression
     public static void main(String [ ] args)
     ^
Droid.java:35: error: illegal start of expression
     public static void main(String [ ] args)
            ^
Droid.java:35: error: ';' expected
     public static void main(String [ ] args)
                  ^
Droid.java:35: error: '.class' expected
     public static void main(String [ ] args)
                                        ^
Droid.java:35: error: ';' expected
     public static void main(String [ ] args)
                                            ^
Droid.java:42: error: reached end of file while parsing
 }
  ^
12 errors


#2

You'll find the issue if you clean up the formatting, specifically indentation/braces
(I suggest keeping that tidy at all times so that you can see what's what)


#3

Geez your right It was an easy error that messed with my code completely,thanks from now on I will be sure to indent & format

...
public int checkBatteryLevel ()
{
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 +" .");
}
} <--

...


#4

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