title: Java file io calculating average and storing in another file
body: <p>I would appreciate knowing how to tackle this type of problems. Thank you in advance.
  Here is the question.</p>
  
  <p>The first line of the files contains two integer numbers ;
  number-of-records                exam-grade</p>
  
  <p>number-of-records        : indicates number of the records in the file.
  exam-grade : indicates the grade of the exam.
  The file follows by students name and their grades.
  Sample File: test1.txt
  Contains four records, and the exam is out of 80. The file follows by the name and grade of the students:  </p>
  
  <pre><code>4  80
  Mary 65.5
  Jack 43.25
  Harry 79.0
  Mike 32.5
  </code></pre>
  
  <p>You have to develop the body of following method:</p>
  
  <p>public static void readWrite(String srcfileName,  String dstFileName)</p>
  
  <p>That reads grades of each student from srcFileName, calculates their grade percent, indicates that if student passed or failed, and finally reports the class average, number of the students passed, and number of the students failed the exam and saves the result in dstFileName.
  The output file for the previous test file should be:</p>
  
  <pre><code>Mary          81.88        passed 
  Jack          54.06        passed 
  Harry         98.75        passed 
  Mike          40.63        failed 
  class average:68.83
  passed: 3
  failed: 1
  </code></pre>
  
  <p>here is the code I wrote for it,</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Lab10Quiz {
    public static void main(String[] args) throws FileNotFoundException 
    {
      // Test cases
      readWrite("test1.txt", "out1.txt");
      readWrite("test2.txt", "out2.txt"); 
      }
  
  /** copies the content of the srcFileName into dstFileName, and add the average of the number to the end of the dstFileName
      @param srcFileName :  souce file name contains double numbers
  @param dstFileName : destination file name 
      */
      public static void readWrite(String srcFileName, String 
  dstFileName) throws FileNotFoundException {
  // Your code goes here
      File output = new File(dstFileName);
      PrintWriter outPut = new PrintWriter(output);
  
      double avg = 0;
      int count = 0;
      double tmp = 0;
  
      Scanner in = new Scanner(new File(srcFileName));
      while (in.hasNextDouble()) {
       tmp = in.nextDouble();
       avg += tmp;
       outPut.println(tmp);
       count ++;
      }
     avg = avg / count;
     outPut.println("Average = " + avg);
    outPut.close();
    }
  }
  </code></pre>