I'm new here and basically I really need some help, I'm trying to validate an if statement (see below) so it will return true and complete the loop is the type of car picked up is a commercial car or a private car, I'm parsing from a .txt file and assigning the data to a local variable called cartype then creating a new instance of either a public or commercial vehicle. The problem is that the program keeps running through the loops without recognising the return should equal true and skimming right over them both. Could you please help!
I'd start with changing comparison operator '==' with equals() method. Afterwards, if problem still persists You may want to start debugging this program to see, if cartype variable holds the value You're looking for.
If you still have problems, try changing the TextReader to a Scanner, unless you have been specifically told to use that class. I can't see anything wrong with your loop. It is most likely a problem with the use of ==. You must be splitting the string successfully, otherwise the invocation of vehicle would cause an Exception.