I'm passing three values to a function from the main. With these values I make a comparison with an IF statement. The condition has to be that all three parameters have to be verified together, with AND(&&) statement.
This is the main when I pass the values
public static void main(String args[]) {
start();
goal();
load_truck("truck", "cdg", "p1");
}
This is the function that receive them
public static void load_truck(String truckL, String placeL, String packL) {
packL = pack;
truckL = truck;
placeL = city;
placeL = airport;
placeL = loc;
if(truckL == "truck" && placeL == "cdg" && pack == "p1") {
at_obj_place(pack = "p1", placeL = "");
in_pk_vehicle(pack = "p1", truck = "truck");
System.out.println("\n"+ "The pack "+ pack + " is on the "+ truck );
}
if(truckL == "truck" && placeL == "cdg" && pack == "p2") {
at_obj_place(pack = "p2", placeL = "");
in_pk_vehicle(pack = "p2", truck = "truck");
System.out.println("The pack "+ pack + "is on the "+ truck );
}
}
The problem is that the comparison with the IF statement is not working. If I insert just one value to compare is working, but with 2 o 3 the IF doesn't work. What is the problem?
EDIT: the problem was how I was filling the variables in the method. I removed and it's working also with ==, not only with equals(). Thanks to everyone