-
-
Save codecademydev/50bf2e846dc30be27cc7 to your computer and use it in GitHub Desktop.
Codecademy export
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
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){ | |
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 bot = new Droid(); | |
bot.activate(); | |
bot.chargeBattery(5); | |
bot.hover(2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment