ChrisCramer247

Platinum Member
Dec 6, 2001
2,171
1
0
I am thourghly confused by this. I am supposed to write a program to read and write off an array. The assignment can be found here if I'm not making much sense: Assignment with a psuedo guide here . Guide. This is what I have so far, I created a token for each but how do I set up this array? We haven't even touched on arrays in class and have to do this so I am COMPLETELY clueless unfortunately.

public class ReadData{
void readData(Inventory[] item)throws IOException{

String line="";

BufferedReader fileInput=new BufferedReader(new FileReader("Sales2.txt"));

//set to receive information by row

for (int row=0;row<5;row++){

line= fileInput.readLine();

StringTokenizer tk = new StringTokenizer(line,",");

String name=tk.nextToken();

String description=tk.nextToken();

String performance=tk.nextToken();

String sales=tk.nextToken();




Am I on the right track or am I completely off? Thanks for the help everyone.

Chris
 

Shuten

Member
Jul 16, 2001
116
0
0
You are on the right track just need to understand what arrays will do.

Inventory[] item is what you should probably be returning not passing into the method.

So if you create an array of Invetory Objects then each time you go through the loop
you would create a new Inventory object, initialize it with the names, prices, etc that you
are getting and return the array of those new objects to the main program. You are close.


If you, or anyone else needs help I provide online java tutoring for a small price.

I also am available for freelance java programming for those in need.

Just PM for more help..