-
-
Save codecademydev/e6789aecc3b5e8cbfb82 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
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) { | |
if (batteryLevel > 100) { | |
batteryLevel = 100; | |
System.out.println(batteryLevel); | |
} | |
else { | |
System.out.println("Droid Charging..."); | |
} | |
batteryLevel = batteryLevel + hours; | |
} | |
public int checkBatteryLevel() { | |
System.out.println("The Battery Level is " + batteryLevel + "Percent!"); | |
} | |
return batteryLevel; | |
public void hover(int feet) { | |
if (feet > 2) { | |
System.out.println("Error! cannot hover above 2 feet."); | |
} | |
else { | |
System.out.println("Hovering..."); | |
} | |
batteryLevel = batteryLevel - 20; | |
System.out.println(batteryLevel); | |
} | |
public static void main(String[] args) { | |
Droid sample = new Droid(); | |
sample.activate; | |
sample.chargeBattery(5); | |
sample.hover(1); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment