Hi there,
Looking for some help if possible.
Almost completed the Build a Droid lesson but stuck on Task 13:
Create new instances and play around with methods. Here are some ideas to get you started:
** Create a energyReport()
method that prints the instance’s batteryLevel
.*
** Create another instance.*
** Create a method energyTransfer()
that exchanges batteryLevel
between instances.*
No matter how much I play around, unable to find solution and progress is blocked as the “Next” button is greyed out until I work it out!
I also ran through the video but it fails to offer a solution (Handily, it leaves Task 13 out).
My up to date code is below, just missing the solution to the final part, Task 13.
I’m a newbie so struggling with this.
Thanks in advance!
public class Droid{
int batteryLevel;
String name;
public Droid(String droidName){
name = droidName;
int batteryLevel = 100;
}
public String toString(){
return "Hello, I am the droid: " + name + “!”;
}
public void performTask(String task){
batteryLevel = batteryLevel -10;
System.out.println(name + " is performing task: " + task);
//System.out.println(batteryLevel);
}
public static void main(String args) {
Droid codey = new Droid(“Codey”);
System.out.println(codey);
codey.performTask(“dancing”);
codey.performTask(“coding”);
}
}