Your Own Droid


#1

Here's my Code:

public class Droid {
int batterylevel = 100;

public Droid(){
}

public void activate(){
System.out.println("Activated.How can i help you?");
batteryLevel -= 5;
System.out.println("Battery level is: " + batteryLevel + " percent.");
}

public void chargeBattery(int hours){
System.out.println("Droid charging...");
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 abouve 2 feet");
  }
  else {
    System.out.println("Hovering...");
    batteryLevel -= 20;
    System.out.println("Battery level is: " + batteryLevel + " percent.");     
}

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

}

And Here's my list of errors. I know it's a huge list but i'm trying to debug it and i don't know how. I don't know. I have not experience debugging in java. Plz i need help.

Droid.java:24: error: illegal start of expression
public int checkBatteryLevel(){
^
Droid.java:24: error: ';' expected
public int checkBatteryLevel(){
^
Droid.java:29: error: illegal start of expression
public void hover(int feet){
^
Droid.java:29: error: illegal start of expression
public void hover(int feet){
^
Droid.java:29: error: ';' expected
public void hover(int feet){
^
Droid.java:29: error: ';' expected
public void hover(int feet){
^
Droid.java:38: error: illegal start of expression
public static void main(String[] args) {
^
Droid.java:38: error: illegal start of expression
public static void main(String[] args) {
^
Droid.java:38: error: ';' expected
public static void main(String[] args) {
^
Droid.java:38: error: '.class' expected
public static void main(String[] args) {
^
Droid.java:38: error: ';' expected
public static void main(String[] args) {
^
Droid.java:44: error: reached end of file while parsing
}
^
Droid.java:45: error: reached end of file while parsing

^

13 errors


#2

Here's what your code looks like when indenting it based on your curly braces.

public class Droid {
 int batterylevel = 100;

 public Droid() {}

 public void activate() {
  System.out.println("Activated.How can i help you?");
  batteryLevel -= 5;
  System.out.println("Battery level is: " + batteryLevel + " percent.");
 }

 public void chargeBattery(int hours) {
   System.out.println("Droid charging...");
   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 abouve 2 feet");
     } else {
      System.out.println("Hovering...");
      batteryLevel -= 20;
      System.out.println("Battery level is: " + batteryLevel + " percent.");
     }
     public static void main(String[] args) {
      Droid r2d2 = new Droid();
      r2d2.activate();
      r2d2.chargeBattery(5);
      r2d2.hover(1);

     }

#3

this the class property you have check the spelling against the ones you are using in your implementation.

Remember that for every opening brace there must be a closing one. Which implies that the total number of braces must be even.Check if you appropriately closed all your methods


#4

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