I have 2 toString methods. They all work fine.
//This toString is the attendant toString.The parameter assign is of type car
public String toString() {
return "Attendant [staffNum=" + staffNum + ", id=" + id + ", available=" + available + ", name=" + name
+ ", assign=" + assign + "]";
}
The toString below is from the car class
public String toString() {
return "Car:" + plateNum + " ID:" + carID + " Position:" + position + " Assigned to:" + assignedTo.getId()
+ "(" + assignedTo.getName() + ")" + " Parked at:" + convert(currTime);
}
My problem is that if I print with the toString attendant it prints fine then for the assign variable since it is type car it calls the car toString. I can't change the car toString cause I use it as it is.
I tried some getmethods calling the car ID and position but it calls for all attendants.
I tried a null check. It would check that if assign is not null it would call the getmethods. This one crash my java.
public String strAssignAttCar(Cars assign){
String result = null;
if(!(assign.equals(null))){
result = Cars.getCarID();
}
and I get this:
Exception in thread "main" java.lang.NullPointerException
at Attendant.strAssignAttCar(Attendant.java:201)
at Attendant.toString(Attendant.java:217)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at Attendant.createAtt(Attendant.java:64)
at Main.main(Main.java:15)
PS:at first and most of the time the attendant parameter assign is null
please help me I dont know what else to try.