What I am trying to do is create cars, assign a name to each car created.
Below is what I have done:
//.....codes
You are assuming that the name of the car is the second instruction:
boolean blnExists =carNames.containsKey(instructions[1]);
but that is correct only for a 'car' command. For the other commands, the name of the car is the first instruction.
You also have an issue here:
if (instructions[1].equals("build")){
car.makeVisible();
}
Variable car
does not reference the car with the given name (you only checked its existence -- you didn't actually retrieve it yet), so the output will not correspond to that car.
There are some other strange things about your code, but nothing that I recognize as erroneous on a quick read-through.