Build A Droid
Thu Sep 22 2022 18:11:02 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
public class Droid{
//instance fields
int batteryLevel;
String name;
//constructor method
public Droid(String droidName){
name = droidName;
batteryLevel = 100;
}
//tostring method
public String toString(){
return "hello, I'm the droid: " + name;
}
//peform task method
public void performTask(String task){
System.out.println(name+" is performing task: "+ task);
batteryLevel = batteryLevel - 10;
}
// method to print energy levels
public void energyReport(){
System.out.println(batteryLevel);
}
//public main method
public static void main(String[] args){
Droid Codey = new Droid("Codey");
System.out.println(Codey);
Codey.performTask("Dancing");
Codey.energyReport();
}
}
content_copyCOPY
https://www.youtube.com/watch?v=z9endqnb6Aw&ab_channel=Codecademy
Comments