Learn Java- Build a Droid

https://www.codecademy.com/courses/learn-java/projects/build-a-droid

Hi everyone!

I am new to Java and programming in general. I am stuck on this free-form project, already on step six. What should be in the parentheses when I create a new instance of Droid named “Codey”?

Thanks in advance.

This is my code so far:

public class Droid {
  
  int batteryLevel = 100;
  String name;
  
  public Droid (String droidName){
    name = droidName;
  }
  
  public static void main(String[] args){
    
    Droid codey = new Droid();
  }
}

then "codey" should be between the parentheses.

instantiate a class, has the following general syntax:

new Class()

in your case, the class is named droid:

new Droid()

when you instantiate a class, the constructor is called:

// the constructor
public Droid (String droidName)

given your constructor has a parameter, you need to provide an argument when the class is instantiated:

new Droid("name of my droid here");
1 Like

Hello, I need your help. I am new in programming, I am stucked on this project buildin a Droid! Can anyone post the hole Project. There are things I can not understand and need help. I need to see the hole code to figure it out. The hints doesnt help. Thank you!

Hi I am new to Java Coding. I’ve manage to figure out the build a droid project. I made a mistake in the code and could not get rid of the mistake. When ever I fix the mistake and run the code again, it kept on returning the code where i’ve made a mistake and this frustrated me to the point that I almost lost it LOL. I manage to bypass this issue by deleting the Droid.java file and reseting it to the default state. Below is my completed code up untill step 12. Step 13 stil playing around with it.

Droid.Java
public class Droid{
String name;
int batteryLevel;

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

}
public void performTask(String task){
batteryLevel = batteryLevel - 10;
System.out.println(name + " is performing task: " + task);
}
public String toString(){
return "Hello, I’m the droid: " + name;
}
public static void main(String args){
Droid codey = new Droid(“Codey”);
System.out.println(codey);
codey.performTask(“dancing”);
codey.performTask(“coding”);

}
}