• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading a .txt file to load objects into an array

 
Zach Ellerbrook
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be pretty basic, because I feel pretty dumb. I have an object with four instances. For my main method, I need to start by reading information from a text file, and load the information into an array of 30 objects. Here's what my teacher says:

Read data and populate the array
Prompt the user for the input file
Read car part specific data from the file
Build CarPart objects with the read data
Put the CarPart objects into the array

The only thing I can do is build the objects in the array, but not with the file data. Maybe I just don't understand what my professor is talking about. I've been trying to follow his instructions line by line.
I never look just for the answer (unless my project is due 2/20 at midnight and there's no other way), but where I can find the information about this.

Thanks in advance for your help. -Zach
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would assume from the description of the problem that the file contains 30 lines and each line of data is formatted in a particular way. Your professor wants you to read the data from the file and use the information on each line to build a CarPart object.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing this was indented like this ...

... to describe the four steps of reading and populating. Have you taken a shot at any of the four? The Ranch works really well when you post code that almost works. Show us how much you can do and where you are stuck. We'll help out from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!