Getting so many errors


#1

getting alot of errors and i dont know why

Droid.java:20: error: illegal start of expression
public int checkBatteryLevel(){
^
Droid.java:20: error: ';' expected
public int checkBatteryLevel(){
^
Droid.java:24: error: illegal start of expression
public void hover(int feet){
^
Droid.java:24: error: illegal start of expression
public void hover(int feet){
^
Droid.java:24: error: ';' expected
public void hover(int feet){
^
Droid.java:24: error: ';' expected
public void hover(int feet){
^
Droid.java:33: error: illegal start of expression
public static void main (String[] args){
^
Droid.java:33: error: illegal start of expression
public static void main (String[] args){
^
Droid.java:33: error: ';' expected
public static void main (String[] args){
^
Droid.java:33: error: '.class' expected
public static void main (String[] args){
^
Droid.java:33: error: ';' expected
public static void main (String[] args){
^
11 errors

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("Droid charging...");
    batteryLevel=batteryLevel+hours;
    
    if(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 myDroid=new Droid();
      myDroid.activate();
      myDroid.chargeBattery(5);
      myDroid.hover(1);
      
    }
    
  }
  
}

#2

Start with the topmost one, fix it, recompile, repeat


#3

I tried everything i can think of, doing what it says doesnt remove the error either.
why does the method need ";" ?


#4

That's not the first error message though. Also, it can't suggest what to change because it doesn't know what you want. All it can do is say "the code doesn't make sense at this place" and then you can have a look there and reconsider what you meant

Start with the first one, the others are immediately below and are likely caused by the same problem in the code and some or all will go away when you fix the first one it encountered


#5

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