-2

I am working on a CPU scheduler for an operating systems course.

There are no compilation errors or warnings, but my output file is incorrect.

What is happening is I am using PrintWriter class to write line by line to an output.

I have the following for loop.

for (int TerminationListIndex = 0; TerminationListIndex < TerminationList.size(); TerminationListIndex++) 
{
 Termination_Info TerminationStats = TerminationList.get(TerminationListIndex);

 Output.println(TerminationStats.getJob_ID() + " " + 
                TerminationStats.getClassType() + " " + 
                TerminationStats.getArrivalTime() + " " + 
                TerminationStats.getLoadingTime() + " " + 
                TerminationStats.getTerminationTime() + " " + 
                TerminationStats.getProcessingTime() + " " + 
                TerminationStats.getTurnaroundTime() + " " + 
                TerminationStats.getWaitingTime());
}

In my eclipse debugger I can view the the TerminationList and see that it holds different objects. The output, however, will print the LAST object in the lists' parameters (Job_ID, Class, ArrTime, LoadTime, TermTime, ProcTime, TurnTime, WaitTime) and I end up with a n output file that has hundreds of lines with the same parameters. In terms of logic, I am fairly confident that it is just some syntax error. Any advice would be greatly appreciated.

M Ferguson
  • 29
  • 3
  • Note that you should use a for each loop here. You don't have to; it's just easier. – Andy Turner Mar 13 '18 at 08:43
  • Are you sure you added `new Termination_Info` for every entry on creation of the list? Did the data there stem from different records? – Joop Eggen Mar 13 '18 at 08:43
  • Please stick to naming conventions. Use lower case at the beginning of your variable and object names, and upper case for class and method names. You're obfuscating your code otherwise and make it hard to read for other developers. E.g. this: `TerminationStats.getJob_ID()` looks like you're accessing a static method of a class, not a method of an object instance. – Max Vollmer Mar 13 '18 at 08:49
  • 2
    Even though you posted an answer yourself, from your question and the code you posted it would've been impossible for anyone to figure out the cause of your problem as you describe in your answer. Please update your question with a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve), so other users can understand your problem and benefit from your answer. – Max Vollmer Mar 13 '18 at 08:51
  • 1
    @MFerguson We're sorry for giving you advice on this advice board, please carry on – Lance Toth Mar 13 '18 at 09:00
  • @MFerguson Uhm, I am sorry that you perceive well-meant free advice in such a way. I will stay away from helping you in the future. Have a nice day! – Max Vollmer Mar 13 '18 at 09:01
  • It is the middle of the night – M Ferguson Mar 13 '18 at 09:58
  • I again apologize. Of course I should've magically known the time zone you live in. I retract wishing you a nice day. Won't ever happen again. It was a pleasure conversing with you. – Max Vollmer Mar 13 '18 at 11:28
  • Dang dude, i hope you have a nice day! – M Ferguson Mar 13 '18 at 12:11

1 Answers1

0

I solved my own problem! Very satisfying as this has been problematic for a long time.

This issue was caused within the declaration of my object class. I had declared the variables as "public static int Parameter", and because they were static ALL of the objects shared those static parameters. Removing the static from the object variables fixed this issue entirely.

M Ferguson
  • 29
  • 3