• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Trying to create an arraylist of objects based on information from a text file

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, this is my main

with this as the class

I don't know if its working or not.
I want this to create an array list of objects.
I don't know if the input is being added into the arraylist correctly or not.
When I try to print it, I get random numbers and letters.
[edit]Add code tags and correct some indentation CR[/edit]
Posts: 79254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

That seems incredibly complicated, using all those indices and substrings to get individual names. Have you found the nextXXX methods of Scanner, or how you can use comma as a delimiter, or how you can use the split() method of String instead? You may need to read about regular expressions, here or here to confirm whether commas are normal characters or meta-characters first however. [I think they are normal characters.]

What sort of output are you getting from printing "information"? Those aren't random numbers at all; you need to check here what you get when you print such a List. You also need to read what it says there about toString, and whether you need a toString method in your AIRTAXICLASS class.

By the way: I presume this is homework; if it is assigned, you will lose marks because of inconsistent braces and indentation. I tidied the code up a bit (read this), but it was difficult to read. Also you have some inconsistencies that you are returning different return types from the field types in the getXXX methods. You will suffer Exceptions if you allow the no-argument constructor to be called.

I have said enough; you should be able to get all your code working now
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic