0

I am trying to write the test result in csv file by using BufferedWriter. The test duration for WAF5-H is 2 seconds. and WAF6-L is 5 seconds. My output file is:

Thu Feb 18 14:01:07 CET 2016;0;WAF5-H;
WAF5-H;
Thu Feb 18 14:01:08 CET 2016;0;WAF5-H;
WAF5-H;
Thu Feb 18 14:01:09 CET 2016;0;WAF5-H;
WAF5-H;

I expected:

Thu Feb 18 14:01:07 CET 2016;0;WAF5-H;
Thu Feb 18 14:01:08 CET 2016;1;WAF5-H;
Thu Feb 18 14:01:08 CET 2016;2;WAF5-H;

until test end then the next job will begin.

for (int i = 0; i < convertedDifference; i++) {
    for (Job currentJob : NEHCalculator.addNewJobInitializeList()) {
        int testDevice = (DeviceGroups.DeviceAList.size() + DeviceGroups.DeviceBList.size()
            + DeviceGroups.DeviceCList.size() + DeviceGroups.DeviceDList.size());
        int times = (int) ((convertedDifference / currentJob.getInterval()) * testDevice);
        for (int t = 0; t < times; t++) {
            // until end of the test date.
            cal.add(Calendar.SECOND, 1);
            beginDate.getTime();
            // write the test date
            bufferedWriter.write(String.valueOf(cal.getTime()));
            bufferedWriter.write(';');
            // write the test total second begin with 0.
            bufferedWriter.write(String.valueOf(i));
            bufferedWriter.write(';');
            double j = 0;

            for (j = 0; j < currentJob.getNeededTestTime(); j++) {
                bufferedWriter.write(currentJob.getJobname());
                bufferedWriter.write(';');
                bufferedWriter.newLine();
            }
        }
        i++;
    }
}

bufferedWriter.close();// Always close files.

The first for loop explain do the test until test ending time. ( actual output violated this because it write down 0 2 times so it will continue until 13442.. . Normally I expected to see 3600 lines in my csv file.

The second for each loop get the selected job list.

Third for loop explains how many time testing will be occured. ( I entered 1 hour testing time and testing time will make every 15 minutes and WAF 5H tests 4 devices. So 4*4*2 = 32 times I would like to see WAF5-H on the csv file.

Last for loop explains the needed time testing for each required machine. ( For WAF 5-H 2 seconds.)

Could someone please help me

1
  • the line bufferedWriter.write(String.valueOf(i)); will write 0 as many times as the inner for loop runs (maybe you wanted to put t instead of i there). And you have an even inner loop (for using j that writes the job name and prints a new line. I think the result you get is pretty much the correct one for your code. Commented Feb 18, 2016 at 13:25

1 Answer 1

1

try this: within your third loop a new line is inserted for each iteration

 for (int i = 0; i < convertedDifference; i++) {
            for (Job currentJob : NEHCalculator.addNewJobInitializeList()) {
               int testDevice = (DeviceGroups.DeviceAList.size() 
                                 + DeviceGroups.DeviceBList.size()
                                 + DeviceGroups.DeviceCList.size() 
                                 +  DeviceGroups.DeviceDList.size());
              int times = (int) ((convertedDifference / currentJob.getInterval()) * testDevice);
              for (int t = 0; t < times; t++) {
                 // until end of the test date.
                 cal.add(Calendar.SECOND, 1);
                 beginDate.getTime();
                 // write the test date
                 bufferedWriter.write(String.valueOf(cal.getTime() +
                    ';' + String.valueOf(i) + ';'));

               //double j = 0; no need to declare double var
              for (int j = 0; j < currentJob.getNeededTestTime(); j++) {
                  bufferedWriter.write(currentJob.getJobname()+ ';');
                ////////////////////////////////////
                /// issue  
                ////////////////////////////////////
                // bufferedWriter.newLine();
              }
          }
      }// end of currentjob loop
     bufferedWriter.newLine(); // ok hear
 }// end first for loop
Sign up to request clarification or add additional context in comments.

5 Comments

I did the change that you recommended but the result is seen as follows Thu Feb 18 15:48:42 CET 2016;0;WAF5-H;WAF5-H; Thu Feb 18 15:48:43 CET 2016;0;WAF5-H;WAF5-H; Thu Feb 18 15:48:44 CET 2016;3;WAF5-H;WAF5-H; Thu Feb 18 15:48:45 CET 2016;3;WAF5-H;WAF5-H; Thu Feb 18 15:48:46 CET 2016;3;WAF5-H;WAF5-H; Thu Feb 18 15:48:47 CET 2016;3;WAF5-H;WAF5-H;
why do u increment i++; inside a for loop ?
Meaningless.. I forgot to delete it. I deleted i++
so let's streamline your spec for a best solution, the bufferW.newLine() should be out of the current job loop, which means that for each currentjob you'll display XXXX;XXXX;X;WAF5-H; (and only here perform new line )
Sorry I could not accept your answer, it could not generate the output that I expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.