import java.io.*; import java.util.*; public class SortListOfStudents { public static void readFromFile(List students, File f) { try(Scanner sc = new Scanner(f)) { while(sc.hasNextLine()) { students.add( new Student(sc.nextInt(), sc.next(), sc.next()) ); } } catch(FileNotFoundException ex) { System.out.println("File \""+f.getName()+"\" was not found!"); } catch(InputMismatchException ex) { System.out.println("Input mismatch while reading with scanner!!!"); ex.printStackTrace(); System.exit(-1); } } public static String toString(List students) { StringBuilder str = new StringBuilder(); for(Student st : students) str.append(st+"\n"); str.append("---------------------------------\n"); return str.toString(); } public static void main(String []args) { if(args.length == 0) { System.out.println("Insufficient number of arguments!\n"); return; } List students = new ArrayList(); readFromFile(students, new File(args[0])); System.out.println(" --- Init Ordering ---\n"); System.out.println(toString(students)); Student.sortLexicographically(students); System.out.println(" --- Lexicographic Ordering ---\n"); System.out.println(toString(students)); Student.sortByAEM(students); System.out.println(" --- AEM Ordering ---\n"); System.out.println(toString(students)); } }