Hi,

I am fairly new to Java and am about to begin a programming course in the next week. I am preparing by completing exercises and am stuck on this particular one.

Basically, i need to read a file in a certain format and calculate some figures and writing the result to another text file.

In dot points:
-read a text file with teh following format
(jobtype, jobname, no_dependent_jobs, depend_job_name, depend_job_name2, etc.)
for example:
A,Plan,0
B,Build,1,Plan
C,Test,2,Plan,Build
C,Maintain,2,Plan,Build
etc.

-I need to calculate stats such as how many jobs are waiting for 'Build' to finish before it can start, number of jobs that can begin immediately etc.
-Write results to a text file.

So far I am able to read and write to a file but I am stuck with the second dot point. How should I go about in calculating the stats of each job. Am i meant to store the data into variables or arrays first? Each row doesn't have a fix format so I couldn't really store it in arrays. I could be completing on the wrong track.

Any advice or assistance is appreciated. Thank you in advance.

I would probably use the "split" method on the String class to break a line into its comma-separated parts. That method returns an array of String values.

You can compute the "number of jobs that can begin immediately" without any additional structures. So it would probably be a good idea to do that before attempting the other requirements. Doing this is called "iterative development."

A Map would probably be a good idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.