import java.util.regex.Pattern; import java.util.regex.Matcher; import java.io.*; import java.util.*; class Program { public static void main(String[] args) throws Exception { String file = args[0]; File f = new File(file); Scanner duke = new Scanner(f); Pattern pattern = Pattern.compile("^((\\w+\\s+)+)(\\d+)\\s+(-{0,1}\\d+)\\s*$"); ArrayList candidates = new ArrayList(); while (duke.hasNextLine()) { String line = duke.nextLine(); System.out.println( "***(" + line + ")***" ); Matcher matcher = pattern.matcher(line); if (matcher.find()) { String name = matcher.group(1); int count = Integer.parseInt( matcher.group(3) ); int sum = Integer.parseInt( matcher.group(4) ); // System.out.println( name + ", " + count + ", " + sum ); Candidate c = new Candidate( name, count, sum ); candidates.add( c ); System.out.println( candidates ); } Collections.sort( candidates ); System.out.println( candidates ); Collections.sort( candidates, new Judge() ); System.out.println( candidates ); } } }