Running code with no errors


#1



Hello,this code runs with no errors so feel free to play and use it as a reference to learn. 
Took me a while to get and I'm still learning!

public class Droid{
  int batteryLevel;
  
  public Droid(){
    batteryLevel=100;
  }//end droid constructor
  
  public void activate(){
    System.out.println("Activated!");
    batteryLevel=batteryLevel-5;
    System.out.println("Battery level is at "+ batteryLevel +" percent!");
  }//end activate method
  public void chargeBattery(int hours){
    System.out.println("Charging....");
    batteryLevel=batteryLevel+hours;
    if(batteryLevel>100){
      batteryLevel=100;
      System.out.println("Battery level is now at "+batteryLevel+ "percent!"); 
    }// end if
    else{
      System.out.println("Your battery level is at "+batteryLevel+" percent");
    }//end else
  }//end chargeBattery method
  public int checkBatteryLevel(){
    System.out.println("Battery level: %"+batteryLevel);
    return batteryLevel;
  }//end checkBatteryLevel method
  public void hover(int feet){
    if(feet>2){
      System.out.println("Error!....Hey man I can't fly that high up!");
    }//end if
    else{
      System.out.println("Hovering....");
      batteryLevel=batteryLevel-20;
      System.out.println("Battery level now at "+batteryLevel+" percent");
    }//end else  
  }// end the hover method
  
  public static void main(String[] args){
    Droid quadCopter= new Droid();
    quadCopter.activate();
    quadCopter.chargeBattery(5);
    quadCopter.hover(2);
  } //ended main

}// end class droid


#2

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