Created
November 9, 2017 06:42
-
-
Save sunnyeyez123/73198e1e3c0b887562a262e44abf7167 to your computer and use it in GitHub Desktop.
A simple Droid (robot) that can be activated, charged, and hover above ground.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A simple Droid (robot) that can be activated, charged, and hover above ground.*/ | |
public class Droid{ | |
int batteryLevel; | |
public Droid(){ | |
batteryLevel =100; | |
} | |
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 above 2 feet.."); | |
}else{ | |
System.out.println("Hovering..."); | |
batteryLevel-=20; | |
System.out.println("Battery level is: " + batteryLevel + " percent."); | |
} | |
} | |
public static void main(String[] args){ | |
Droid r2 = new Droid(); | |
r2.activate(); | |
r2.chargeBattery(5); | |
r2.hover(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment