/**
 * 
 */
package lab06;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * @author Thomas
 *
 */
public class Section {
	/**
	 * 
	 */
	public Section() {
		students=new ArrayList<Student>();
	}

	ArrayList<Student> students;

	/**
	 * @param e
	 * @return
	 * @see java.util.ArrayList#add(java.lang.Object)
	 */
	public boolean add(Student e) {
		return students.add(e);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Section cs140b = new Section();
		  cs140b.readFile("students.txt");
		  cs140b.sort();
		  cs140b.report();

	}
	
	public boolean readFile(String fileName) {
		try {
			Scanner in = new Scanner(new File(fileName));
			while(in.hasNext()) {
				String name = in.next();
				boolean male = in.nextBoolean();
				Student ff = new Student(0,name,male);
				this.add(ff);
			}
			in.close();
			return true;
		} catch(FileNotFoundException e) {
			System.out.println("Unable to open file: " + fileName);
		}
		return false;	
	}
	
	public void sort() { Collections.sort(students); }
	
	public void report() {
		for(Student s : students) {
			System.out.println(s);
		}
	}

}
