I’m trying to remove my planes when the user inputs that they have landed. This doesn’t work. Can anyone see any problems with my code to why it does not work.
Here is my code:
Plane
static boolean isLanded;
public boolean isLanded() {
return isLanded;
}
public void setLanded(boolean isLanded) {
this.isLanded = isLanded;
}
PlaneStore
public void removeLandedPlanes(PlaneStore store)
{
if(Plane.isLanded = true)
{
airlineMap.remove(store);
}
}
MainApp
case 3:
System.out.println("Remove Landed Planes.");
airlineMap.removeLandedPlanes(airlineMap);
airlineMap.print();
break;
HashMap declaration in PlaneStore
HashMap<String, TreeMap<String, Plane>> airlineMap;
public PlaneStore()
{
airlineMap = new HashMap<String, TreeMap<String, Plane>>();
}
And then in main PlaneStore airlineMap = new PlaneStore();
What this seems to have done is make every plane object to have isLanded to false.
Note that this is assigning the value
truetoPlane.isLanded. You want to use the comparison operator==instead of=.And since this is a
booleanalready, you should actually leave out the== truecompletely: