Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/Droid.java Secret

Created Oct 15, 2020
Embed
What would you like to do?
Codecademy export
public class Droid{
String name;
int batteryLevel;
public Droid (String droidName) {
name = droidName;
batteryLevel = 100;
}
public String toString(){
return ("Hello, I'm the droid:" + name);
}
public void performTask(String task){
System.out.println(name + " is performing task " + task);
batteryLevel -=10;
}
public void energyReport(){
System.out.println("The current battery level is: " + batteryLevel);
}
public static void main (String[]args){
Droid codey = new Droid("Codey");
System.out.println(codey);
codey.performTask ("Tickling.");
codey.energyReport();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment