Build a Droid Code

Correct Code

public class Droid{
  int batteryLevel;
  String name;

  public Droid(String droidName){
    name = droidName;
    batteryLevel = 100;
  }

  public String toString(){
    String intro = "Hello, I'm the droid: " + name;
    return intro;
  }

  public void performTask(String task){
    System.out.println(name + " is performing task: " + task);
    batteryLevel -= 10;
  }

  public String energyReport(){
    String status = name + "'s battery level is: " + batteryLevel;
    return status;
  }

  public static void main(String[] args){
    Droid codey = new Droid("Codey");
    System.out.println(codey);

    codey.performTask("cook dinner");
    codey.performTask("solve a math problem");
    codey.performTask("learn to code in Java");
    System.out.println(codey.energyReport());
  }
}


Select a repo