Key to Value associations

前端 未结 2 818
时光说笑
时光说笑 2021-01-03 09:12

What I am trying to do is create cars, assign a name to each car created.

Below is what I have done:

//.....codes
         


        
2条回答
  •  再見小時候
    2021-01-03 09:37

    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.

提交回复
热议问题