import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;


public class Students {

	ArrayList<Student> students;
	
	public Students() {
		students = new ArrayList<Student>();
	}
	
	public void add(Student stu) {
		students.add(stu);
	}
	
	public double mean() {
	   double sum = 0.0;
	   for (Student stu : students) {
		   sum += stu.mark();
	   }
	   return sum / students.size();
	}
	
	public String showReport() {
		String res = "";
		
		Collections.sort(students);
		
		 for (Student stu : students) {
			   res += stu.showReport() + "\n";
		   }
		 res += "------------\n";
		 res += "Mean : " + mean() + "\n";
		 return res;
		
	}
	
	public static Students loadStudents(String fileName) {
        try {
			BufferedReader buf = new BufferedReader(new FileReader(fileName));
			Students students = new Students();
			String line;
			while ((line = buf.readLine()) != null) {
				students.add(Student.parseStudent(line));
			}
			return students;
			
		} catch (FileNotFoundException e) {
			System.out.println("Can not find file : " + fileName);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
	
}

