package project_1;

import java.io.File;
import java.io.PrintWriter;

public class PrintOnFile {
    /*
     * This Class print the Information in many Files
     * */
	
	LinkedList<Course> CoursesList;
	
	LinkedList<Course> sortedYearList;
	LinkedList<Student> sortedNameList;
	String s="";
	public PrintOnFile(LinkedList<Course> coursesList, LinkedList<Course> sortedYearList,
			LinkedList<Student> sortedNameList) {
		CoursesList = coursesList;
		
		this.sortedYearList = sortedYearList;
		this.sortedNameList = sortedNameList;
	}

	PrintWriter w;

	
	public void print(){
		try{
			w= new PrintWriter("Each_Course.txt");
		    eachCourse();
		    allStudent();
		    allCourses();
		}
		catch (Exception e) {
			
		}
	}
	
	
	private void eachCourse(){
		for (int i = 0; i < CoursesList.getSize(); i++) {
			s+=CoursesList.getIndexData(i).getName()+"\r\n";
			for (int j = 0; j < CoursesList.getIndexData(i).getList().getSize(); j++) {
				s+=CoursesList.getIndexData(i).getList().getIndexData(j).toString()+"\r\n";
			}
			w.println(s);
			s="";
			w.print("-------------------"+"\r\n");
	
		}
		w.close();
	}
	private void allStudent(){
		try{
			w = new PrintWriter("All_Students.txt");
		
			for (int i = 0; i < sortedNameList.getSize(); i++) {
				s+=sortedNameList.getIndexData(i).toString()+"\r\n";
			}
			w.print(s);
			s="";
			
			w.close();
		}
		catch (Exception e) {
			System.exit(0);
		}
	}
	private void allCourses(){
		try{
			w = new PrintWriter("All_Courses.txt");
		
			for (int i = 0; i < sortedYearList.getSize(); i++) {
				s+=sortedYearList.getIndexData(i).toString()+"\r\n"
						+"\r\n";
			}
			w.print(s);
			s="";
			
			w.close();
		}
		catch (Exception e) {
			System.exit(0);
		}
	}
	
	
}
