Course Statistics Using Arrays and Files I wanted to get some feedback here on my solution, because the course I am using is not allowing me to submit any answers.


  Objectives:
  
  Write a Java program that:
  
  
  Create a grades.txt file with some grades inputted in
  Reads these grades from the file and stores it into an ArrayList
  After storing all elements into the ArrayList return the max, min, and average grade of the list
  Return an Arraylist without any duplicate grades. All duplicated grades must be removed
  




import java.io.*;
import java.lang.reflect.Array;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
       File file = new File("grades.txt");

      PrintWriter output = new PrintWriter(file);
      output.println("12.5");
      output.println("19.75");
      output.println("11.25");
      output.println("10");
      output.println("15");
      output.println("13.25");
      output.println("14");
      output.println("9");
      output.println("10");
      output.println("19.75");
      output.close();

      // Reading from the file //

        ArrayList&lt;Double&gt; gradesString = new ArrayList&lt;Double&gt;();

        Scanner input = new Scanner(file);

        while(input.hasNext())
        {
            String line = input.nextLine();
            gradesString.add(Double.parseDouble(line));
        }

        double result = 0;

        for(Double i : gradesString)
        {
            result += i;
        }

        double mean = result / gradesString.size();

        LinkedHashSet&lt;Double&gt; hashSet = new LinkedHashSet&lt;&gt;(gradesString);

        ArrayList&lt;Double&gt; gradesWithoutDuplicates = new ArrayList&lt;Double&gt;(hashSet);


        System.out.println("The grades are: " + gradesString);
        System.out.println("The highest grade is: " + Collections.max(gradesString));
        System.out.println("The lowest grade is: " + Collections.min(gradesString));
        System.out.println("The average is: " + mean);
        System.out.println("The grades list without duplicates is: " + gradesWithoutDuplicates);


    }

}


Output:



The grades are: [12.5, 19.75, 11.25, 10.0, 15.0, 13.25, 14.0, 9.0, 10.0, 19.75]
The highest grade is: 19.75
The lowest grade is: 9.0
The average is: 13.45
The grades list without duplicates is: [12.5, 19.75, 11.25, 10.0, 15.0, 13.25, 14.0, 9.0]
Exception handling

It is not customary to let the main method throw an exception. At the very least you can catch the base Exception class and use printStackTrace() to print the error message and related debug info. 

IO handling


This program only deals with one file.  However, it is good practice to remember to close every external resource.  That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.
Java 7 also introduced the "new io" java.nio package that improves IO handling in Java.   the Files.readAllLines() is a convenient method that reads whole file into List of Strings (and also internally handles the external resource). (alas, no equivalent writeAllLines())


Naming conventions

gradesString is a List of Double items. the name is very confusing.