I'm really stuck on this code because I can't seem to understand how to access data member into another class in java. I need someone to explain this to me properly.
I have my customer class with the following data members:
name
startLocation
endLocation
When I try to access these data members in my separate .java file I get errors at this line:
System.out.println("Driver #" + ID + " has dropped off " + getname + " at " + getendLocation);
I can't just have that code without bringing the data members into the other .java file. Can someone explain how I can take this code and make it visible in my seperate file?
public class Customer
{
private String name;
private String startLocation;
private String endLocation;
public Customer (String name, String startLocation, String endLocation)
{
this.name = name;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
public String getname()
{
return name;
}
public String getstartLocation()
{
return startLocation;
}
public String getendLocation()
{
return endLocation;
}
}
Now here is where I'm stuck. When I went to the tutor center at my school the student butted in to helped me told me I needed to make a main constructor. So I did and this is it. He told me I also needed to add a name = new name in there too, but when I did add that he suddenly told me to forget everything he told me and to go back with my way of doing it (I didn't have a way worked out yet, was just messing around). Can someone finish explaining what he was trying to show me?
public Customer()
{
this.name = name;
this.StartLocation = startLocation;
this.endLocation = endLocation;
}