Build a Droid Help

public class Droid{
  //instances
  int batteryLevel;
  String name;
  //Constructor
  public Droid(String droidName){
    name = droidName;
    batteryLevel = 100;
  }
  //methods
  public String introduce(){
    batteryLevel = batteryLevel - 1;
    return "Hi, my name is " + name + "!";
  }
  public void performTask(String task){
    System.out.println("Codey is performing task: " + task);
    batteryLevel = batteryLevel - 10;
  }
  public void energyReport(){
    System.out.println(name + " has " + batteryLevel + " percent left.");
  }
  public void energyTransfer(int percent, String droidName){
    batteryLevel = batteryLevel - percent;
    droidName.batteryLevel = droidName.batteryLevel + percent;
    System.out.println(name + " has transfered " + percent + " percent(s) to " + droidName + ".");
  }
  public static void main(String[] args){
    Droid Yimo = new Droid("Yimo");
    Droid Elena = new Droid("Elena");
    System.out.println(Elena.introduce());
    System.out.println(Yimo.introduce());
    Yimo.performTask("cook");
    Yimo.energyReport();
    Elena.energyTransfer(5,Yimo);
    Elena.energyReport();
    Emma.energyReport();
  }
}

I am trying to get the droids to interact with each other directly without creating huge amounts of loops to check which droid we are talking about with the droidName part. I get the errors:

Droid.java:24: error: cannot find symbol
    droidName.batteryLevel = droidName.batteryLevel + percent;
             ^
  symbol:   variable batteryLevel
  location: variable droidName of type String
Droid.java:24: error: cannot find symbol
    droidName.batteryLevel = droidName.batteryLevel + percent;
                                      ^
  symbol:   variable batteryLevel
  location: variable droidName of type String
Droid.java:34: error: incompatible types: Droid cannot be converted to String
    Emma.energyTransfer(5,Emma);
                          ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
3 errors

Sorry if this is kinda long :blush:

No problem. I think you have to revise your code at these points

Droid.java:34: error: incompatible types: Droid cannot be converted to String
    Emma.energyTransfer(5,Emma);

This one means you’re trying to put a non-string variable where only a string is accepted.

However, you never instantiated Emma (at least in this code you’ve shown) so that’ll throw another error. Emma.energyTransfer(5, “Emma”) should probably work. Same goes for Elena.energyTransfer(5,Yimo);, should probably be “Yimo” or you’ll get another error.

second issue comes at this line droidName.batteryLevel = droidName.batteryLevel + percent;. The parameter you use means that droidName is going to be a string. But a string can’t have properties like batteryLevel. You’re going to have to figure out how to get that type changed.

 public void energyTransfer(int percent, String droidName){
    batteryLevel = batteryLevel - percent;
    droidName.batteryLevel = droidName.batteryLevel + percent;
    System.out.println(name + " has transfered " + percent + " percent(s) to " + droidName + ".");
  }

And that’s what the errors are alluding to, those 2 things.

implies that the compiler can’t do what you’re asking it to do. Since in this case you are referencing the property of an object, you’d have to think what can go wrong in that reference. Is it that the property doesn’t exist? that the object doesn’t exist? that the syntax is wrong?