A 39-year-old train enthusiast who has spent a third of his life behind bars for joyriding on trains in New York City was sentenced to a maximum of three years in prison yesterday for attempted grand larceny for trying to take a Long Island Rail Road M-7 locomotive and train from a railyard in Jamaica , Queens , last June .