Train Simulation Problems
Andrew Jackson

Andrew Jackson @sonandrew

About: "It only seems impossible until it is done" - Nelson Mandela

Location:
Minnesota
Joined:
Aug 16, 2019

Train Simulation Problems

Publish Date: Mar 21 '20
5 4

Hey everyone,

I am having trouble with this Train Simulation that I am working on for school. I don't know what I have done wrong. I am not getting any errors but the output is just wrong. I am having problems with how many stations are being visited and also the station names. The station name that is being printed is [Ljava.lang.String;@27716f4 and I don't know why.

You can find the main class MainClass and support class SubwayTrain
--> here.

If anyone can help I would greatly appreciate it.

Test data I am using

Number of Stations: 3
Home Station Number: 33
Maximum Capacity: 10
Enter fullscreen mode Exit fullscreen mode

Comments 4 total

  • vilfrim
    vilfrimMar 22, 2020

    Station name printing worked for me but you should change borrowedInput.next().toUpperCase().charAt(0) to borrowedInput.nextInt() when you are reading integer value from user. I would create a small helper method to read the valid integer input so I wouldn't have to implement validity check every time I read integer.

    • Andrew Jackson
      Andrew JacksonMar 22, 2020

      Yes I fixed that problem and are you finding "borrowedInput.next()" in a validation method in MainClass? If so this is not validating an integer. It is to validate the character input from the user when they are choosing a menu option.

      • vilfrim
        vilfrimMar 22, 2020

        You are using borrowedInput.next().toUpperCase().charAt(0) method to read user input even when you are asking an integer value like in validateMaximumCapacity and validateNumberOfStations methods. In these cases you should use borrowedInput.nextInt() instead. Using borrowedInput.next().toUpperCase().charAt(0) method when you are asking a single character, like in main menu, is fine.

        • Andrew Jackson
          Andrew JacksonMar 22, 2020

          Life saver!!! I didn’t realize I was doing that. Omg thank you. I thought I already fixed that a while ago. Well I guess that’s what you get when you copy and try to change one of your components into something else. Lol

Add comment