This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Trying to create an arraylist of objects based on information from a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to create an arraylist of objects based on information from a text file" Watch "Trying to create an arraylist of objects based on information from a text file" New topic
Author

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

toby mercer
Greenhorn

Joined: May 03, 2009
Posts: 1
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]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to create an arraylist of objects based on information from a text file